> ## Documentation Index
> Fetch the complete documentation index at: https://moengage.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Real-Time Triggers

> Set up device-triggered push notifications that fire instantly when a user performs an event on iOS.

Real-time device triggers are push notifications that are triggered instantly in the device whenever a trigger event(configured while creating the campaign) is tracked with the SDK [trackEvent:](https://www.moengage.com/docs/developer-guide/ios-sdk/data-tracking/basic/tracking-events) method. In this case, the notifications are triggered in the device, which enables you to post notifications even in offline scenarios.

<Info>
  Real-Time Triggers are available from SDK version [4.0.0](/release-notes/sdks/ios)
</Info>

# SDK Installation

## Install using Swift Package Manager (Recommended)

MoEngageRealTimeTrigger is supported through SPM from SDK version 1.2.0. To integrate, use the  GitHub url [https://github.com/moengage/apple-sdk.git](https://github.com/moengage/apple-sdk.git) for SDK versions equal and above 9.23.0, or [https://github.com/moengage/MoEngage-iOS-SDK.git](https://github.com/moengage/MoEngage-iOS-SDK.git) for other SDK versions link and set the branch as master or required version.

## Install using CocoaPod

<Info>
  **Information**

  CocoaPods is being deprecated. MoEngage recommends using Swift Package Manager for all new integrations. For more info on CocoaPods, refer to [CocoaPods Integration Guide](https://www.moengage.com/docs/developer-guide/ios-sdk/sdk-integration/basic/integration-through-cocoa-pods).
</Info>

From MoEngage-iOS-SDK version 8.2.0, MoEngageRealTimeTrigger module is separated from the SDK to a separate module as MoEngageRealTimeTrigger and hence has to be added separately.

Integrate the RealTimeTrigger framework by adding the dependency in the podfile as shown below.

<CodeGroup>
  ```ruby Ruby wrap theme={null}
  pod 'MoEngage-iOS-SDK/RealTimeTrigger',
  ```
</CodeGroup>

Now run `pod install` to install the framework

# Manual Syncing

MoEngage SDK syncs all the real-time trigger campaigns whenever the app is **launched OR comes to the foreground**. But in case its needed to manually sync the device triggers for any of the background tasks, use [*syncRealTimeTriggers(forAppID:andCompletionHandler:)*](https://moengage.github.io/ios-api-reference/Classes/MoEngageSDKRealTimeTrigger.html#/c:@M@MoEngageRealTimeTrigger@objc\(cs\)MoEngageSDKRealTimeTrigger\(im\)syncRealTimeTriggersForAppID:andCompletionHandler:) as shown below:

<CodeGroup>
  ```swift Swift wrap theme={null}
  MoEngageSDKRealTimeTrigger.sharedInstance.syncRealTimeTriggers(forAppID: "YOUR_APP_ID") { rtSyncCompleted in
            if(rtSyncCompleted){
               print("Real-Time trigger sync successfull")
        }
  }
  ```

  ```objective-c Objective C wrap theme={null}
  [[MoEngageSDKRealTimeTrigger sharedInstance] syncRealTimeTriggersForAppID:@"YOUR APP ID" andCompletionHandler:^(BOOL rtSyncCompleted) {
        if (rtSyncCompleted) {
              NSLog(@"Real-Time trigger sync successfull");
        }
  }];
  ```
</CodeGroup>

# Additional Callbacks

<Warning>
  **Note**

  For iOS 10 and above, MoEngage SDK uses the UserNotification framework for triggering notifications and relies on the callbacks from **UNUserNotificationCenter** to obtain and process the notification payload. Therefore, make sure the SDK methods are called in UNUserNotificationCenter delegate callbacks as mentioned in this [doc](https://www.moengage.com/docs/developer-guide/ios-sdk/push/basic/ios-push-integration-tutorial#step-1-implement-notification-service-extension-nse).
</Warning>
