> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-analytics-query-api-docs.mintlify.site/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://developers.moengage.com/hc/en-us/articles/4403922636308) method. In this case, the notifications are triggered in the device, which enables you to post notifications even in offline scenarios.

<Warning>
  Real-Time Triggers are available from SDK version [4.0.0](https://developers.moengage.com/hc/en-us/articles/4404198236564-Change-Log#v4-0-0-0-33)
</Warning>

# SDK Installation

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.

[![Version](https://img.shields.io/cocoapods/v/MoEngageRealTimeTrigger.svg?style=flat)](http://cocoapods.org/pods/MoEngageRealTimeTrigger)

## Install using CocoaPod

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

<CodeGroup>
  ```auto Ruby theme={null}
  pod 'MoEngageRealTimeTrigger','~>1.2.0'
  ```
</CodeGroup>

Now run `pod install` to install the framework

## Install using Swift Package Manager

MoEngageRealTimeTrigger is supported through SPM from SDK version 1.2.0. To integrate, use the following github url link and set the branch as master or version as 1.2.0 and above [https://github.com/moengage/MoEngage-iOS-RealTimeTrigger.git](https://github.com/moengage/MoEngage-iOS-RealTimeTrigger.git)

# 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 `syncRealTimeTriggersWithCompletionBlock:` as shown below:

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

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

# Additional Callbacks for version below iOS 10

<Warning>
  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://developers.moengage.com/hc/en-us/articles/43960004257428-iOS-Push-Integration-Tutorial#h_01K45FKD0XDH4X776R47JA04GJ).
</Warning>

For iOS versions below iOS 10 call `didReceieveNotificationinApplication: withInfo:openDeeplinkUrlAutomatically:` method of MoEngage SDK as shown below.

<CodeGroup>
  ```swift Swift theme={null}
  func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
          if let userInfo = notification.userInfo  {
              MoEngage.sharedInstance().didReceieveNotificationinApplication(application, withInfo: userInfo, openDeeplinkUrlAutomatically: true)
          }
  }
  ```

  ```objectivec Objective-C theme={null}
  -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
      NSDictionary* userInfo = notification.userInfo;
      [[MoEngage sharedInstance]didReceieveNotificationinApplication:application withInfo:userInfo openDeeplinkUrlAutomatically:YES];
  }
  ```
</CodeGroup>
