Skip to main content

Adding push capability

  1. Inside your Target select signing and capabilities
  2. 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 allows you to display alerts, add a badge to the app icon, or play sounds whenever a notification is delivered. In this type of authorization, the request is made the first time user launches your app. If the user denies the request, you can’t send subsequent prompts to send the notification.
Explicit authorization is default authorization method as it automatically sets alert, sound and badge as soon as the user allows this request.
Provisional Authorization (Supported in iOS 12.0 and above) are sent quietly to the users -they don’t interrupt the user with a sound or banner. Also, they will not be shown when your app is in foreground. First time this type of notifications are sent, user is asked to “Keep” or “Turn off” the notifications. Further notifications continue to be sent if they click on “Keep”.

Adding delegate methods for push handling

Changes in Notification Service Extension

Adding Notification Service Extension

  1. In Xcode go to File > New > Target.
  2. Select Notification Service Extension from the template list.
  3. 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

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.
For SDK version 1.1.0 onwards, add the SDK to your Podfile as a dependency to the Notification Service Extension using the GitHub source and run pod install:
For SDK versions till 1.0.1, add the SuprSendSwift SDK to your Podfile as a dependency to the 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.
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.