Skip to content

Integration via app delegate composition

Andrey Kadochnikov edited this page Jun 2, 2016 · 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, as a parameter:

    // Swift
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    	MobileMessaging.startWithApplicationCode("your_application_code")
    	...
    }	
    // Objective-C
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    	[MobileMessaging startWithApplicationCode:@"your_application_code"];
    	...
    }
  3. Setup notification types that you want to use and register for remote notifications:

    // Swift
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    	MobileMessaging.startWithApplicationCode("your_application_code")
    
    	let userNotificationTypes: UIUserNotificationType = [.Alert, .Badge, .Sound]
    	let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
    	application.registerUserNotificationSettings(settings)
    	application.registerForRemoteNotifications()
    	...
    }
    // Objective-C
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    	[MobileMessaging startWithApplicationCode:@"your_application_code"];
    
    	UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
    	UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
    	[application registerUserNotificationSettings:settings];
    	[application registerForRemoteNotifications];
    	...
    }
  4. 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];
    }
  5. 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];
    }
Clone this wiki locally