Skip to content

Integration via app delegate composition

Davor Komušanac edited this page Dec 5, 2022 · 15 revisions
  1. Import the library:

    // Swift
    import MobileMessaging
    // Objective-C
    @import MobileMessaging;
  2. Start MobileMessaging service using your Infobip Application Code, obtained in step 2, and preferable notification type as parameters:

    // Swift
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        MobileMessaging.withApplicationCode(<#your application code#>, notificationType: <#for example MMUserNotificationType(options: [.alert, .sound])#>)?.start()
    	...
    }	
    // Objective-C
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        MMUserNotificationType *userNotificationType = [[MMUserNotificationType alloc] initWithOptions:<#for example @[MMUserNotificationType.alert, MMUserNotificationType.sound]#>;
        [[MobileMessaging withApplicationCode: <#your application code#> notificationType: userNotificationType] start:nil];
    	...
    }
  3. Override method application:didRegisterForRemoteNotificationsWithDeviceToken: in order to inform Infobip about the new device registered:

    // Swift
    func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    	MobileMessaging.didRegisterForRemoteNotificationsWithDeviceToken(deviceToken)
    }
    // Objective-C
    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    	[MobileMessaging didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
    }
  4. Override method application:didReceiveRemoteNotification:fetchCompletionHandler: in order to send notification delivery reports to Infobip:

    // Swift
    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    	MobileMessaging.didReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler)
    }
    // Objective-C
    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
    	[MobileMessaging didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
    }
  5. Override method application:didReceiveLocalNotification(for Objective-C) or application:didReceive:(for Swift 3) in order the MobileMessaging SDK to be able to handle incoming local notifications internally:

    // Swift
    func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
    	MobileMessaging.didReceiveLocalNotification(notification)
    }
    // Objective-C
    -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        [MobileMessaging didReceiveLocalNotification:notification];
    }
Clone this wiki locally