SDK Installation
iOS Native
Push Notification for iOS
6min
cooee delivers engagement content with push notification hence, push notification plays the main role with cooeesdk ios needs to be set up with apns https //developer apple com/library/archive/documentation/networkinginternet/conceptual/remotenotificationspg/apnsoverview\ html#//apple ref/doc/uid/tp40008194 ch8 sw1 follow the below steps for push notification setup add capability to app to get started with push notifications you will need to add the following capability to your app push notification background modes app group then you have to update background mode and app group make sure to enable background fetch , remote notification & background processing in background mode in the app group add a group with the name group com letscooee your app id your capability window should look like below configure app now you have to update appdelegate to let cooeesdk know about n otification action , foreground mode and devicetoken \#import \<usernotifications/usernotifications h> \#import "cooeesdk/cooeesdk swift h" @interface appdelegate () \<unusernotificationcenterdelegate> @end @implementation appdelegate \ (bool)application (uiapplication )application didfinishlaunchingwithoptions (nsdictionary )launchoptions { self viewcontroller = \[\[mainviewcontroller alloc] init]; \[appcontroller configure]; // request notification permission & register for remote notification unusernotificationcenter center = \[unusernotificationcenter currentnotificationcenter]; center delegate = self; \[center requestauthorizationwithoptions (unauthorizationoptionsound | unauthorizationoptionalert | unauthorizationoptionbadge) completionhandler ^(bool granted, nserror nullable error) { if( !error ) { // once permission granted register for remote notification dispatch async(dispatch get main queue(), ^{ \[\[uiapplication sharedapplication] registerforremotenotifications]; }); } else { // handle error thrown by permission request nslog( @"error %@ %@", error localizedfailurereason, error localizeddescription ); } }]; return \[super application\ application didfinishlaunchingwithoptions\ launchoptions]; } \ (void)application (uiapplication )application didregisterforremotenotificationswithdevicetoken (nsdata )devicetoken { // send device token to the cooee \[\[cooeesdk getinstance] setdevicetokenwithtoken\ devicetoken]; } \ (void)usernotificationcenter (unusernotificationcenter )center willpresentnotification (unnotification )notification withcompletionhandler (void (^)(unnotificationpresentationoptions))completionhandler { // cooee can show only in app while app is in foreground here cooee will check for there notification and // decide what action should be taken on foreground notification if push notification do not belong to // cooee then default \[ badge, alert, sound] is return completionhandler(\[\[cooeesdk getinstance] presentnotification\ notification]); } \ (void)usernotificationcenter (unusernotificationcenter )center didreceivenotificationresponse (unnotificationresponse )response withcompletionhandler (void (^)(void))completionhandler { // cooee will perform click action associated with push notification \[\[cooeesdk getinstance] notificationaction\ response]; completionhandler(); } @end\@main class appdelegate uiresponder, uiapplicationdelegate, unusernotificationcenterdelegate { func application( application uiapplication, didfinishlaunchingwithoptions launchoptions \[uiapplication launchoptionskey any]?) > bool { appcontroller configure() // request notification permission & register for remote notification unusernotificationcenter current() delegate = self let authoptions unauthorizationoptions = \[ alert, badge, sound] unusernotificationcenter current() requestauthorization( options authoptions, completionhandler { granted, error in if granted { // once permission granted register for remote notification dispatchqueue main async { application registerforremotenotifications() } }else{ // handle error thrown by permission request nslog("error \\(error? localizeddescription)") } } ) return true } func application( application uiapplication, didregisterforremotenotificationswithdevicetoken devicetoken data) { // send device token to the cooee cooeesdk getinstance() setdevicetoken(token devicetoken) } func usernotificationcenter( center unusernotificationcenter, willpresent notification unnotification, withcompletionhandler completionhandler @escaping (unnotificationpresentationoptions) > void) { // cooee can show only in app while app is in foreground here cooee will check for there notification and // decide what action should be taken on foreground notification if push notification do not belong to // cooee then default \[ badge, alert, sound] is return completionhandler(cooeesdk getinstance() presentnotification(notification)) } func usernotificationcenter( center unusernotificationcenter, didreceive response unnotificationresponse, withcompletionhandler completionhandler @escaping () > void) { // cooee will perform click action associated with push notification cooeesdk getinstance() notificationaction(response) completionhandler() } } notification service extension now you have to add notification service extension https //developer apple com/documentation/usernotifications/modifying content in newly delivered notifications to your app once you add notification service extension in the app then add the following capability in your extension push notification app group then you have to update app group to make communication between your app and extension in app group add/enable group with the name group com letscooee your app id add cooee app id in info plist of your notification service extension once you're done with the above steps; your extension capability window should look like below code update to access cooeesdk in your notification service extension you have to update your podfile as below platform \ ios, '13 0' target 'your app name' do use frameworks! pod 'cooeesdk', ' > x x x' target 'your notification service extension name' do \# adding below line will fetch parent's target pods inherit! \ search paths end end update didreceive method in notificationservice with the below code \ (void)didreceivenotificationrequest (unnotificationrequest )request withcontenthandler (void (^)(unnotificationcontent nonnull))contenthandler { self contenthandler = contenthandler; // cooee will modify content and deliver back to notification service extension self bestattemptcontent = \[cooeenotificationservice updatecontentfromrequest\ request]; self contenthandler(self bestattemptcontent); }override func didreceive( request unnotificationrequest, withcontenthandler contenthandler @escaping (unnotificationcontent) > void) { self contenthandler = contenthandler bestattemptcontent = cooeenotificationservice updatecontentfromrequest(request) // cooee will modify content and deliver back to notification service extension if let bestattemptcontent = bestattemptcontent { contenthandler(bestattemptcontent) }else{ contenthandler(request content) } } that's it!! you are done with push notification integration now start testing your integration with cooee dashboard