Skip to content

Integrate iOS / iPad SDK

The iOS SDK is required to enable push notifications in your application. It handles device registration with the Push0 API and ensures the device can receive notifications.

Important

iOS SDK is split into two components: iOS Client SDK and iOS Notification Extension SDK. Both are mandatory - neither works without the other, so both must be included in your project.

When integrated, the SDK automatically registers the device, obtains the push token from the system, and securely sends it to the Push0 backend. This registration step links the device to your application, allowing notifications to be delivered reliably.

Without the SDK, devices cannot register with the Push0 service and will not be able to receive push notifications.

1. Adding Push0 iOS client SDK to your project

1 - Add Remote notifications capability

In Signing & capabilites in your main app target select Remote notifications capability

Important

This is very important.

Xcode capability remote notifications - add project

2 - Go to Package dependencies in your project settings. Click + button

Xcode capability remote notifications - add project

Copy the following URL to your clipboard and paste it into the Search or enter Package URL field.

https://bitbucket.org/push0/push0-ios-sdk.git
Select Exact version and select the newest version number. Click Add package

Xcode capability remote notifications - add project
Select your main app target. Click Add package

Xcode capability remote notifications - add project

3 - Code: AppDelegate.swift

Setting your apiKey and appId

import UIKit
import Push0SDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let apiKey = "my_api_key"
        let applicationId = "my_app_id" // Example: "app_g454h65"

        Push0.initialize(
            applicationId: applicationId,
            apiKey: apiKey,
            customUserId: nil,
            userEmail: nil,
            logLevel: .debug,
            developerMode: false, // Enable ONLY in Developer mode. Don't use on TestFlight or Production builds!
            launchOptions: launchOptions)

    // Requesting notification permission. Without this your app wont be able to receive push notifications
        Push0.requestNotificationPermission(owner: self) { granted in
            print("AppDelegate / App has notification permissions -> \(granted)")
        }

        Push0.setOnInitializedListener(owner: self) {
            print("AppDelegate / Push0 initialized")
        }


        Push0.setOnNotificationReceived(owner: self) { notification in
            print("AppDelegate / Push0 new notification -> \(notification)")
        }

        Push0.setOnNotificationClicked(owner: self) { notification in
            print("AppDelegate / Push0 notification clicked -> \(notification)")
        }

        Push0.setOnNotificationButtonClicked(owner: self) { actionId, notification in
            print("AppDelegate / Push0 notification button clicked / actionId -> \(actionId) / notification -> \(notification)")
        }



        return true
    }

}


3 - Enabling developer mode

Warning

Use only in Developer mode. Don't use on TestFlight or Production builds!In developer mode push notifications are sent to APNS sandbox environment.
There is no option to disable developer mode on current device.

        Push0.initialize(
            applicationId: applicationId,
            apiKey: apiKey,
            customUserId: nil,
            userEmail: nil,
            logLevel: .debug,
            developerMode: true,
            launchOptions: launchOptions)


4 - LogLevel

Indicates level of logs.

let logLevel = Push0LogLevel.debug

        Push0.initialize(
            applicationId: applicationId,
            apiKey: apiKey,
            customUserId: nil,
            userEmail: nil,
            logLevel: logLevel,
            developerMode: false,
            launchOptions: launchOptions)

5 - Setting user email or custom id

Indicates level of logs.

let email = "[email protected]"
let customUserId = "my_backend_custom_user_id"

let logLevel = Push0LogLevel.debug

// Can be set during initialisation:
        Push0.initialize(
            applicationId: applicationId,
            apiKey: apiKey,
            customUserId: customUserId,
            userEmail: email,
            logLevel: .debug,
            developerMode: false,
            launchOptions: launchOptions)

// or anywhere on any screen (email + customUserId at the same time):
Push0.setCustomUserIdAndEmail(customUserId: customUserId, email: email)

// or separately on any screen:
Push0.setUserEmail(email)
Push0.setCustomUserId(customUserId)

6 - User tags

Adding or removing device tags

let tag = "my_tag"

// Add
Push0.addDeviceTag(tag)

// Remove
Push0.removeDeviceTag(tag)

7 - User logout

Should be used when your user has logged out of your application or there is a need to remove current FCM push token.

Push0.unregister()

Warning

This method unregisters current user device and creates a new one.

2. Adding Push0 iOS client Notification Service Extension SDK to your project

1 - Go to your project settings. In Targets section Add Target by clicking + button

Important

Without Notification Service Extenstion your app won't be able to register notification actions.

Xcode capability remote notifications - add project

2 - Search for Notification Service Extension. Select it. Click Next button.

Xcode capability remote notifications - add project

3 - Type your notification service extension target name for example NotificationServiceExtension. Click finish

Xcode capability remote notifications - add project

4 - Go to Package dependencies in your project settings. Click + button

Xcode capability remote notifications - add project
Copy the following URL to your clipboard and paste it into the Search or enter Package URL field.

https://bitbucket.org/push0/push0-sdk-notification-extension.git
Select Branch or Exact version and select the newest version number. Click Add package

Xcode capability remote notifications - add project

Select your main Notification Service Extension target. Click Add package

Xcode capability remote notifications - add project

5 - Code: NotificationService.swift (in your Notification Extension Service)

Xcode capability remote notifications - add project

Warning

Without this your app will not be able to register notification actions.

The code

import UserNotifications
import Push0SDKNotificationExtension

class NotificationService: UNNotificationServiceExtension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var receivedRequest: UNNotificationRequest?

    override func didReceive(
        _ request: UNNotificationRequest,
        withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void
    ) {

        self.contentHandler = contentHandler
        self.receivedRequest = request


        Push0NotificationExtension.handleReceivedNotificationExtensionRequest(
            request: request,
            withContentHandler: contentHandler
        )
    }

    override func serviceExtensionTimeWillExpire() {

            Push0NotificationExtension.serviceExtensionTimeWillExpire(
                request: receivedRequest,
                contentHandler: contentHandler
            )
    }
}

3. Keychain access group

Important

Without correct keychain access group configuration - your app won't be able to display notifications and register notification actions.

Copy the following group id:

com.push0.client.kc.group

1 - Go to your project settings. In Targets section select you main app target

2 - To the right of + Capability select All. Click + Capability.

Xcode capability remote notifications - add project

3 - Type Keychain and select Keychain sharing

Xcode capability remote notifications - add project

4 - In Keychain Sharing in Keychain Groups click the '+' and paste above group id.

Xcode capability remote notifications - add project

5 - Select your Notification Service Extension target. To the right of + Capability select All. Click + Capability.

Xcode capability remote notifications - add project

6 - Type Keychain and select Keychain sharing

Xcode capability remote notifications - add project

7 - In Keychain Sharing in Keychain Groups click the '+' and paste above group id.

Xcode capability remote notifications - add project
All setup correctly!