{"_id":"55ee66a073d3941700f760e5","parentDoc":null,"user":"55d2bd8e2463351700f67dd7","version":{"_id":"55e67aab9cc7c62b00c4a1ed","project":"55e67aaa9cc7c62b00c4a1ea","__v":10,"createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["55e67aac9cc7c62b00c4a1ee","55e67b5556007d23005fee7d","55e67b5dde6fef23009480ca","55e680efde6fef23009480db","55e6829485a9741900314e99","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","589b8e1fdbb7cd190026732c","58b8ca5e3265d70f001788d4"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"__v":4,"category":{"_id":"589b8e1fdbb7cd190026732c","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"version":"55e67aab9cc7c62b00c4a1ed","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-02-08T21:31:11.878Z","from_sync":false,"order":6,"slug":"advanced-techniques","title":"Advanced Techniques"},"project":"55e67aaa9cc7c62b00c4a1ea","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-08T04:40:00.143Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":14,"body":"## Manual Integraton\n\n### Token Handling\nSome third party libraries and frameworks can interfere with the Carnival SDK's ability to collect push tokens and to handle incoming notifications. If devices are registering with Carnival, but without push tokens, you may need to manually forward notifications and device tokens to the Carnival iOS SDK.\n\nTo do this, you will need to override a few delegate methods on your application delegate.\n\nIn `application:didRegisterForRemoteNotificationsWithDeviceToken:` call the `setDeviceTokenInBackground` class method on Carnival:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\\n  // Forward the device token data to the Carnival iOS SDK\\n  [Carnival setDeviceTokenInBackground:deviceToken];\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \" func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {\\n  // Forward the device token data to the Carnival iOS SDK\\n  Carnival.setDeviceTokenInBackground(deviceToken)\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n### Notification Handling\n\nTo forward notifications to the Carnival iOS SDK call the `handleNotification:` method on Carnival with the notification received from `application:didReceiveRemoteNotification:` and `applicationDidReceiveRemoteNotification:fetchCompletionHandler:` where appropriate:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo\\n  {\\n\\t  // Forward the notification's userInfo to the Carnival iOS SDK\\n\\t  [Carnival handleNotification:userInfo];\\n  }\\n\\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {\\n  // Forward the notification's userInfo to the Carnival iOS SDK\\n  [Carnival handleNotification:userInfo];\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {\\n\\t// Forward the notification's userInfo to the Carnival iOS SDK\\n  Carnival.handleNotification(userInfo)\\n}\\n    \\nfunc application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {\\n\\n\\t// Forward the notification's userInfo to the Carnival iOS SDK\\n  Carnival.handleNotification(userInfo)\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]\n## Foreground Presentation\nAs of iOS 10, notifications may appear inside the app while the app is open. By default, the Carnival SDK hides these, and when In App Messages are associated, a roll-down In App Notification for those are shown. You can override this behaviour by conforming an object `UNUserNotificationCenterDelegate` and implementing `userNotificationCenter:willPresentNotification:`. See an example below.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {\\n    completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: :::at:::escaping (UNNotificationPresentationOptions) -> Void) {\\n        completionHandler([.alert, .badge, .sound])\\n}\",\n      \"language\": \"swift\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"manually-passing-push-tokens-to-carnival","type":"basic","title":"iOS Notification Handling"}

iOS Notification Handling


## Manual Integraton ### Token Handling Some third party libraries and frameworks can interfere with the Carnival SDK's ability to collect push tokens and to handle incoming notifications. If devices are registering with Carnival, but without push tokens, you may need to manually forward notifications and device tokens to the Carnival iOS SDK. To do this, you will need to override a few delegate methods on your application delegate. In `application:didRegisterForRemoteNotificationsWithDeviceToken:` call the `setDeviceTokenInBackground` class method on Carnival: [block:code] { "codes": [ { "code": "- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {\n // Forward the device token data to the Carnival iOS SDK\n [Carnival setDeviceTokenInBackground:deviceToken];\n}", "language": "objectivec" }, { "code": " func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {\n // Forward the device token data to the Carnival iOS SDK\n Carnival.setDeviceTokenInBackground(deviceToken)\n}", "language": "swift" } ] } [/block] ### Notification Handling To forward notifications to the Carnival iOS SDK call the `handleNotification:` method on Carnival with the notification received from `application:didReceiveRemoteNotification:` and `applicationDidReceiveRemoteNotification:fetchCompletionHandler:` where appropriate: [block:code] { "codes": [ { "code": "- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo\n {\n\t // Forward the notification's userInfo to the Carnival iOS SDK\n\t [Carnival handleNotification:userInfo];\n }\n\n- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler {\n // Forward the notification's userInfo to the Carnival iOS SDK\n [Carnival handleNotification:userInfo];\n}", "language": "objectivec" }, { "code": "func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {\n\t// Forward the notification's userInfo to the Carnival iOS SDK\n Carnival.handleNotification(userInfo)\n}\n \nfunc application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {\n\n\t// Forward the notification's userInfo to the Carnival iOS SDK\n Carnival.handleNotification(userInfo)\n}", "language": "swift" } ] } [/block] ## Foreground Presentation As of iOS 10, notifications may appear inside the app while the app is open. By default, the Carnival SDK hides these, and when In App Messages are associated, a roll-down In App Notification for those are shown. You can override this behaviour by conforming an object `UNUserNotificationCenterDelegate` and implementing `userNotificationCenter:willPresentNotification:`. See an example below. [block:code] { "codes": [ { "code": "- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {\n completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);\n}", "language": "objectivec" }, { "code": "func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {\n completionHandler([.alert, .badge, .sound])\n}", "language": "swift" } ] } [/block]