Step 3.3: Initialising SDK

The Push SDK has to be initialised in the App Delegate class

In AppDelegate add import NotiveraSDK

Create two references to hold the SDK and PushologiesUserNotificationDelegate

var sdk: Notivera?
var userNotificationDelegate: NotiveraUserNotificationDelegate?

In the lifecycle method**didFinishLaunchingWithOptions** instantiate the SDK, using the API credentials gathered in previous steps.

// Inject the credentials
sdk = Notivera(
    apiKey: “MyPushologiesAPIKey”,
    apiSecret: “MyPushologiesSecretKey”,
    inAppOpenDelay: 5000,
    tenantID: “MyTenantID”
)

// Set the UserNotificaionDelegate
userNotificationDelegate = NotiveraUserNotificationDelegate(sdk: sdk)
UNUserNotificationCenter.current().delegate = userNotificationDelegate

// Set CustomerID (optional)
sdk?.customerID = "YourID"

Add authorisation prompts after initialising the SDK, this includes notification and location permission. This is optional and can be called at any place inside your app based on your convenience.

// Use whichever prompts your application requires
Task {
    await sdk?.showPushNotificationAuthorisationPrompt()
}
Task {
    await sdk?.showLocationAuthorisationPrompt()
}
Task {
// altertnatively use  below to prompt both in one call
    await sdk?.showAuthorisationPrompts()
}

Please use appropriate **Purpose String **for your location permission. Otherwise the prompts may not appear in your device.

To find your deviceID please use the below method

sdk?.deviceID

Print your deviceID in our console and check your device info in the portal.

👍 Find your device in the subscriber explorer

Portal: https://portal.pushologies.com/subscriber-explorer

You should be able to see your device information and session details as well. If you have any issues seeing your subscriber in the portal, please check our troubleshooting guide.

Notification Service Extension

Navigate to the NotificationService class

Replace the above NotificationService class with this new class that inherits from NotificationServiceExtension.

import NotiveraSDK

class NotificationServiceExtension: NotiveraServiceExtension {

    override func didReceive(
        _ request: UNNotificationRequest,
        withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
    ) {
       if request.isNotiveraRequest {
           super.didReceive(request, withContentHandler: contentHandler)
       }
    }

}

Now the class will look like this