Push Notifications for iOS apps
Add Apptics framework to your Apple project
By now, you would have already integrated Apptics with your Apple project. If not, refer to the integration guide.
- Open the .xcworkspace file and make sure you have enabled push notification and app group identifier in your application.
- Go to your root project in Xcode and select the main app target. Navigate to the Signing & Capabilities tab.
- If push notifications are not enabled, click + Capability and add push notifications.
- Click + Capability again and add Background modes.
- Also, enable the remote notifications.
Add notification service extension
The AppticsNotificationServiceExtension enables your iOS app to receive the rich notifications with images, buttons, and badges. It is also essential for Apptics' confirmed devliery analytics stats.
- In Xcode, navigate to File > New > Target.
- Select the Notification Service Extension and click Next.
- Give a name to the NotificationServiceExtension and click Finish.
- When prompted to activate the scheme after selecting Finish, click Cancel to avoid activating it.
- In Xcode, select the NotificationServiceExtension target.
- Go to general settings. Set the minimum deployment to match your main application target. This should be iOS 14.5 or higher.
Add app groups
App groups enable your app and the NotificationServiceExtension to share data when a notification is received, even if the app is not running. This is essential for implementing the badges and confirmed deliveries.
- Select your main app target in Xcode.
- Go to Signing & Capabilities and click on + Capability.
- Choose App groups.
- Click on + to add a new group.
- Set the app groups container name to 'group.MAIN_BUNDLE_IDENTIFIER.apptics', where the MAIN_BUNDLE_IDENTIFIER should match the bundle identifier of your main application.
- Click OK to save the app group for your main app target. Repeat the steps for the NotificationServiceExtension Target.
- Select the NotificationServiceExtension Target > Signing & Capabilities > + Capability > App groups.
- In app groups, click + button to add a new group.
- Set the app group container to 'group.MAIN_BUNDLE_IDENTIFIER.apptics', making sure NOT to include 'NotificationServiceExtension' in the name.
- Replace the MAIN_BUNDLE_IDENTIFIER with the bundle identifier of your main application.
Add AppticsMessaging and AppticsNotificationServiceExtension framework
- Install the Apptics iOS SDK with Cocoapod.
- Specify pod 'AppticsMessaging and AppticsNotificationServiceExtension' in your podfile.
- The podfile will look something similar to the one shown below.
Copied
Note: Pass the app group identifier to the run script as mentioned in the podfile above --app-group-identifier="group.MAIN_BUNDLE_IDENTIFIER.apptics".
- From your terminal, navigate to the project root folder and run the pod install --repo-update.
Import and initialize in main application
Integrate the notification service extension
- In the Xcode project navigator, select the NotificationServiceExtension folder.
- Locate and open the NotificatioService.m (for Obj-C) or NotificationService.swift (for Swift) file.
- Replace the whole content of the file with the following code.
Configure notification service
Upload p12 certificate
Refer to this link for detailed steps on how to upload your p12 certificate to Apptics.