Learn how to configure your Push Notifications for iOS
PageSense allows you to send push notifications to your applications from our dashboard. Please follow the steps to send your first push notification to your application. Please note to test remote push notifications you need to connect your actual iOS device. The remote push notifications don't work on simulator.
To send push notifications on your iOS Application using PageSense dashboard, you first need to upload key or certificate from Apple developer account. There are 2 ways to configure push notifications.
How to acquire and upload a .p8 file? (recommended)
Go to Keys section and click on a new key using Add button(+)
Choose a unique name for key and select Apple Push Notification service(APNs) checkbox. Click Continue and then Confirm.

Note and save the key ID. Click Download
to generate and save the key.
Note: Remember you have to save the key in a secured place because you can't download key more than once. Do not rename Auth key file, and upload it as it is to the PageSense dashboard, as shown in step 6.Now go to PageSense dashboard and go to Settings > Channels > Mobile Push. Choose iOS tab andchoose Provider authentication token (Auth key) under Authentication Type as given in the following picture.

You will get an option to Upload Auth Key. Upload your .p8 key from Apple developer account and enter Team and Bundle ID.
You will get your Team ID from Apple Developer Account. Go to Membership tab and get your Team ID. Your app's Bundle ID can be found in Xcode. Select the appropriate mode for sending push notifications and click Save.
We recommend that you create and upload an APNs Auth Key rather than uploading .p12 certificate for the following reasons:
i) No need to re-generate the push certificate every year.
ii) One auth key can be used for all your apps – this avoids the complication of maintaining different certificates.
How to acquire and upload a .p12 certificate?
If you have configured .p8 file successfully, you can skip this and directly go to Step 2.
Alternatively, you may utilize Apple’s older authentication scheme (.p12 SSL certificates). These certificates automatically expire every year and will require you to regenerate and re-upload them.
Log in to Apple Developer account, and navigate to the Program Resources tab and select Certificates, Identifiers & Profiles.

Select Certificates tab and add a new certificate using the '+' sign

Select Apple Push Notification service SSL under Services and click Continue

Choose App ID of your project from the dropdown.

Now Apple will ask you to upload a Certificate signing request. On your MAC open Keychain Access and navigate to Certificate Assistant. Select Request a Certificate From a Certificate Authority.

Selecting this option directs you to the Certificate Assistant. Select Request is > Saved to Disk and leave the email address blank. Click Continue.
Now Upload the certificate on Apple developer account as requested in 5.
Download the certificates generated and open it with the Keychain Access application.
In Keychain Access, click My Certificates and locate your push certificate.
Select, right-click and export it as a .p12 file and use a temporary password. (It will be required when uploading your certificate to PageSense dashboard).

Navigate to Manage Settings > Settings in the dashboard and upload your certificate under Apple Push Certificate. The passphrase is your temporary password.
Info: You can upload either your development or production push certificates to the dashboard for your distribution provisioning profile apps, but you can only have one active push certificate at a time.
If you wish to test push notifications in a production environment once your app goes live in the App Store, we recommend setting up a separate app group or app for your development environment
Step 2: Enable the Push Notifications Capability

In your Xcode project settings, with the Target selected, click the Signing & Capabilities tab and then click the + Capability button to add. Type “push” in the filter field and select Push Notifications. This will enable the Push Notifications Capability in your project.
Step 3: Registering for push notifications
1. First import User Notifications in your App Delegate. The push integration code has to be written in App delegate file and should be written on main thread. To configure the PageSense SDK to send you push notifications, you should have followed all steps till integrate
in iOS quick start guide document. To setup push notifications in the application, implement the UNUserNotificationCenterDelegate in your AppDelegate.
2. To register the device with the APNS, add the following code to the application:didFinishLaunchingWithOptions:
Delegate method of your app delegate:
- func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
- // Override point for customization after application launch.
- PageSense.integrate()
- UNUserNotificationCenter.current().delegate = self
- registerForPushNotifications()
- return true
- }
- func registerForPushNotifications() {
- UNUserNotificationCenter.current().requestAuthorization(options: [
- .badge, .sound, .alert
- ]) { granted, _ in
- guard granted else { return }
- DispatchQueue.main.async {
- UIApplication.shared.registerForRemoteNotifications()
- }
- }
- }
- func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
- PageSense.setPushToken(deviceToken: deviceToken)
- }
It is a mandatory step to send push notifications to an iOS Application. The first time your app makes this authorization request, the system prompts the user to grant or deny the request and records the user’s response.
Push Impressions
You can now raise and record push notifications delivered onto your user's iOS devices. To raise Push Impressions for iOS, you must enable the Notification Service Extension.


Notification Service Extension is a separate and distinct binary embedded in your app bundle. Before displaying a new push notification, the system will call your Notification Service Extension to allow you to call the Notification Viewed method for your Application. In function didReceive of Notification Service file write the following:
- override func didReceive(_ request: UNNotificationRequest,
withContentHandler contentHandler: @escaping (UNNotificationContent)
-> Void) {
- self.contentHandler = contentHandler
- bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
- if let bestAttemptContent = bestAttemptContent {
- // Modify the notification content here...
- bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
-
- contentHandler(bestAttemptContent)
-
- PageSense.trackPushNotificationReceived(notificationContent: request.content)
- }
- }
We’ve designed this documentation to guide you every step of the way. If you need further assistance or have any questions, don’t hesitate to contact us at
support@zohopagesense.com - we’re always here to help!