> For the complete documentation index, see [llms.txt](https://docs.luciq.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.luciq.ai/references/sdk-event-handlers/set-pre-sending-handler.md).

# Set Pre-Sending Handler

API reference for Luciq's pre-sending handler. Add report data before submission, with completion-based event handling on iOS SDK 19.12.0 and later.

Use this handler to add extra data before sending a bug or crash report. The handler runs in the background.

On iOS SDK 19.12.0 and later, use `onBeforeSendingEventHandler`. By default, no handler is registered. Register it after starting Luciq and keep your work brief. Call `completion(event)` once after modifying the event. Do not dispatch the completion block to the main queue. Changes apply only to that report.

{% hint style="warning" %}
On iOS, `willSendReportHandler` is deprecated as of SDK 19.12.0. It still works but will be removed in a future release. Migrate to `onBeforeSendingEventHandler` and call the completion block instead of returning a report.
{% endhint %}

{% tabs fullWidth="true" %}
{% tab title="iOS - Swift" %}

```swift
Luciq.onBeforeSendingEventHandler = { event, completion in
    event.append(tags: ["checkout"])
    event.append(userAttributes: ["subscription": "premium"])
    event.set(userData: "Checkout context")
    let data = Data("Report context".utf8)
    event.addFileAttachment(data: data, fileName: "context.txt")
    completion(event)
}
```

{% endtab %}

{% tab title="iOS - ObjC" %}
{% code overflow="wrap" %}

```objectivec
Luciq.onBeforeSendingEventHandler = ^(LCQEvent *event, void (^completion)(LCQEvent * _Nullable)) {
    [event appendTags:@[@"checkout"]];
    [event appendUserAttributes:@{@"subscription": @"premium"}];
    [event setUserData:@"Checkout context"];
    NSData *data = [@"Report context" dataUsingEncoding:NSUTF8StringEncoding];
    [event addFileAttachmentWithData:data fileName:@"context.txt"];
    completion(event);
};
```

{% endcode %}
{% endtab %}

{% tab title="And - Java" %}

```java
Luciq.onReportSubmitHandler(new Report.OnReportCreatedListener() {
            @Override
            public void onReportCreated(Report report) {
                
            }
        });
```

{% endtab %}

{% tab title="And - Kotlin" %}

```kotlin
Luciq.onReportSubmitHandler{report -> }
```

{% endtab %}

{% tab title="RN" %}

```javascript
Luciq.onReportSubmitHandler((report) => {
    // Attach logs and extra data to reports.
});
```

{% endtab %}
{% endtabs %}

On iOS, the new handler receives an `Event` in Swift (`LCQEvent` in Objective-C). Use the event methods shown above; the legacy report logging methods are not available on the event. Setting either `onBeforeSendingEventHandler` or `willSendReportHandler` replaces the other handler. Setting either property to `nil` clears the registered handler.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.luciq.ai/references/sdk-event-handlers/set-pre-sending-handler.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
