APNS Push Integration
Integrate APNS Push in your Swift application
Adding push capability
- Inside your Target select signing and capabilities
- Click on +capabilities and select Push Notifications
Registering for push notifications
AppDelegate should implement UNUserNotificationCenterDelegate
from UserNotifications
and then add registerForPush
method to AppDelegate and call that method inside application(_:didFinishLaunchingWithOptions:)
.
Asking user permission
Explicit Authorization
Explicit Authorization
Provisional Authorization
Provisional Authorization
Adding delegate methods for push handling
Changes in Notification Service Extension
Adding Notification Service Extension
-
In Xcode go to File > New > Target.
-
Select Notification Service Extension from the template list.
-
Then in Next popup give it any product name, select your team, select swift language and click finish.
After clicking on “Finish”, a folder will be created with your given product name.
Installing SuprSend SDK in Notification Service
Swift Package Manager (SPM)
Swift Package Manager (SPM)
In Xcode, go to File > AddPackages to add a new dependency.
In that search bar, add suprsend-swift-sdk project github url https://github.com/suprsend/suprsend-swift-sdk
and keep the default version settings and click Add Package
button.
In second dialog box, select your Notification Service target from dropdown and click Add Package
button.
Cocoapods
Cocoapods
Add the SuprSendSwift SDK to your Podfile as dependency to Notification Service Extension like below and then run pod install
.
Adding code in Notification Service
Paste the below code in NotificationService.swift file. Replace YOUR_PUBLIC_KEY
with your public key.
Handling deep links
By default SDK will handle only http deeplinks. If you want to handle custom deeplinks, implement SuprSendDeepLinkDelegate
in AppDelegate class and add the below code.
Final AppDelegate.swift file
Example of AppDelegate.swift
file with all the above code.