{"_id":"5d8aaaedad4f2b0064417d9f","project":"55e67aaa9cc7c62b00c4a1ea","version":{"_id":"5b720760c44b7600034b7a08","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"forked_from":"5b1f2cbdfd653400031d8d9f","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["5b720760c44b7600034b79a7","5b720760c44b7600034b79a8","5b720760c44b7600034b79a9","5b720760c44b7600034b79aa","5b720760c44b7600034b79ab","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5b720760c44b7600034b79ac","5b720760c44b7600034b79ad","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"API V6","version_clean":"1.4.0","version":"1.4"},"category":{"_id":"5b720760c44b7600034b79ac","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"version":"5b720760c44b7600034b7a08","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"user":"5b0b7a46a26e6400036604fd","__v":0,"parentDoc":null,"metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2019-09-24T23:46:53.789Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"By default the iOS SDK will integrate with the push notification handling in your application, allowing it to process notification data and settings without any manual integration steps on your part. However, there are some libraries that can conflict with this auto integration and some situations where you may desire more manual control over this handling. In these cases, you can turn off auto integration using the following method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[Carnival setAutoIntegrationEnabled:NO];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"Carnival.setAutoIntegrationEnabled(false)\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Note\",\n  \"body\": \"You must disable auto integration before calling the `[Carnival startEngine:]` method.\"\n}\n[/block]\nOnce auto integration has been turned off, there are some extra methods you will need to implement in your application in order for the SDK to receive push notification related data.\n\n### UNUserNotificationCenterDelegate methods\nThese methods are called in your UNUserNotificationCenterDelegate implementation. You need to set this in the UNUserNotificationCenter in order to handle push notifications in your app from iOS 10+.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {\\n    // Pass the notification to the SDK\\n    [Carnival handlePresentNotification:notification];\\n  \\n    // Call the completion handler\\n    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: :::at:::escaping (UNNotificationPresentationOptions) -> Void) {\\n    // Pass the notification to the SDK\\n    Carnival.handlePresent(notification)\\n  \\n    // Call the completion handler\\n    completionHandler([.badge, .sound])\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThe `userNotificationCenter:willPresentNotification:withCompletionHandler:` method is called when a notification is received when the application is running in the foreground.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {\\n    // Pass the notification response to the SDK.\\n\\t\\t[Carnival handleNotificationResponse:response];\\n\\n    // Call the completion handler\\n    completionHandler();\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {\\n    // Pass the notification response to the SDK.\\n    Carnival.handle(response)\\n  \\n    // Call the completion handler\\n    completionHandler()\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThe `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:` method is called when a notification has been interacted with by the user, which can be:\n* Tapping the notification\n* Tapping a notification action\n* Dismissing the notification, if custom dismissal handling has been requested for that category\n\n### UNUserNotificationCenter methods\nAfter requesting push notification authorization from the UNUserNotificationCenter you can update the platform with the authorized notification options using the following method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {\\n  \\t// Send push authorization settings to platform\\n    [Carnival syncNotificationSettings];\\n}];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in\\n    // Send push authorization settings to platform\\n    Carnival.syncNotificationSettings()\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n### UIApplicationDelegate methods\nThese methods are called in your application's UIApplicationDelegate implementation and include token handling and push payload handling.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\\n    [Carnival setDeviceTokenInBackground:deviceToken];\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\\n    Carnival.setDeviceTokenInBackground(deviceToken)\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThe `application:didRegisterForRemoteNotificationsWithDeviceToken:` method is called when an app has registered for remote notifications using the `[[UIApplication sharedApplication] registerForRemoteNotifications]` method. It will be called to return the APNS token to the application, which must then be supplied to in the SDK in order for the platform to send push notifications to the device.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {\\n    // Pass the notification payload to the SDK.\\n    [Carnival handleNotificationPayload:userInfo];\\n  \\n    // Call the completion handler\\n    completionHandler(UIBackgroundFetchResultNewData);\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {\\n    // Pass the notification payload to the SDK.\\n    Carnival.handleNotificationPayload(userInfo)\\n  \\n    // Call the completion handler\\n    completionHandler(.newData)\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\nThe `application:didReceiveRemoteNotification:fetchCompletionHandler:` method serves different functions on different versions of iOS. For iOS 8 & 9 it is the sole source of data for received notifications. For iOS 10+ it is called at the time the notification is received (if possible). If your app has requested permission to launch in the background for remote notifications and the app is not running, it will launch the app into the background if it can to handle this method. However, it will not launch if the user has manually cleared the app from memory.","excerpt":"SDK auto integration details","slug":"ios-auto-integration","type":"basic","title":"iOS: Auto Integration"}

iOS: Auto Integration

SDK auto integration details

By default the iOS SDK will integrate with the push notification handling in your application, allowing it to process notification data and settings without any manual integration steps on your part. However, there are some libraries that can conflict with this auto integration and some situations where you may desire more manual control over this handling. In these cases, you can turn off auto integration using the following method. [block:code] { "codes": [ { "code": "[Carnival setAutoIntegrationEnabled:NO];", "language": "objectivec" }, { "code": "Carnival.setAutoIntegrationEnabled(false)", "language": "swift" } ] } [/block] [block:callout] { "type": "info", "title": "Note", "body": "You must disable auto integration before calling the `[Carnival startEngine:]` method." } [/block] Once auto integration has been turned off, there are some extra methods you will need to implement in your application in order for the SDK to receive push notification related data. ### UNUserNotificationCenterDelegate methods These methods are called in your UNUserNotificationCenterDelegate implementation. You need to set this in the UNUserNotificationCenter in order to handle push notifications in your app from iOS 10+. [block:code] { "codes": [ { "code": "- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {\n // Pass the notification to the SDK\n [Carnival handlePresentNotification:notification];\n \n // Call the completion handler\n completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound);\n}", "language": "objectivec" }, { "code": "func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {\n // Pass the notification to the SDK\n Carnival.handlePresent(notification)\n \n // Call the completion handler\n completionHandler([.badge, .sound])\n}", "language": "swift" } ] } [/block] The `userNotificationCenter:willPresentNotification:withCompletionHandler:` method is called when a notification is received when the application is running in the foreground. [block:code] { "codes": [ { "code": "- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {\n // Pass the notification response to the SDK.\n\t\t[Carnival handleNotificationResponse:response];\n\n // Call the completion handler\n completionHandler();\n}", "language": "objectivec" }, { "code": "func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {\n // Pass the notification response to the SDK.\n Carnival.handle(response)\n \n // Call the completion handler\n completionHandler()\n}", "language": "swift" } ] } [/block] The `userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:` method is called when a notification has been interacted with by the user, which can be: * Tapping the notification * Tapping a notification action * Dismissing the notification, if custom dismissal handling has been requested for that category ### UNUserNotificationCenter methods After requesting push notification authorization from the UNUserNotificationCenter you can update the platform with the authorized notification options using the following method. [block:code] { "codes": [ { "code": "[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {\n \t// Send push authorization settings to platform\n [Carnival syncNotificationSettings];\n}];", "language": "objectivec" }, { "code": "UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in\n // Send push authorization settings to platform\n Carnival.syncNotificationSettings()\n}", "language": "swift" } ] } [/block] ### UIApplicationDelegate methods These methods are called in your application's UIApplicationDelegate implementation and include token handling and push payload handling. [block:code] { "codes": [ { "code": "- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\n [Carnival setDeviceTokenInBackground:deviceToken];\n}", "language": "objectivec" }, { "code": "func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {\n Carnival.setDeviceTokenInBackground(deviceToken)\n}", "language": "swift" } ] } [/block] The `application:didRegisterForRemoteNotificationsWithDeviceToken:` method is called when an app has registered for remote notifications using the `[[UIApplication sharedApplication] registerForRemoteNotifications]` method. It will be called to return the APNS token to the application, which must then be supplied to in the SDK in order for the platform to send push notifications to the device. [block:code] { "codes": [ { "code": "- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {\n // Pass the notification payload to the SDK.\n [Carnival handleNotificationPayload:userInfo];\n \n // Call the completion handler\n completionHandler(UIBackgroundFetchResultNewData);\n}", "language": "objectivec" }, { "code": "func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {\n // Pass the notification payload to the SDK.\n Carnival.handleNotificationPayload(userInfo)\n \n // Call the completion handler\n completionHandler(.newData)\n}", "language": "swift" } ] } [/block] The `application:didReceiveRemoteNotification:fetchCompletionHandler:` method serves different functions on different versions of iOS. For iOS 8 & 9 it is the sole source of data for received notifications. For iOS 10+ it is called at the time the notification is received (if possible). If your app has requested permission to launch in the background for remote notifications and the app is not running, it will launch the app into the background if it can to handle this method. However, it will not launch if the user has manually cleared the app from memory.