Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Enabling push notifications with the Connect SDK on iOS

Updated on July 18, 2018

Push notifications allow users to instantly receive important information on their mobile devices. To enable push notifications in an iOS native mobile app that uses the Connect SDK, you must perform server-side configuration and make changes to the project files for the iOS native mobile app.

Server-side configuration

Perform the following server-side configuration steps:

  1. Go to Apple Development Center to create a provisioning profile for the iOS mobile app that you are developing.
  2. Create a Pega 7 Platform application and do the following steps:
    1. On the Mobile tab of the Application rule form, click Custom mobile app.
    2. Create an iOS certificate set that specifies the push notifications certificate file.
      Remember that to use an iOS certificate set, you must also use a mobile provisioning file. For more information, see Configuring push notifications on iOS.
    3. In the Certificate set name list, select the new iOS certificate set that you created in the previous step.
    4. Click Save.
  3. Send push notifications by using the Push Console or by adding a push notifications shape to a workflow in your application. For more information, see Accessing the Push Console and Adding the push notifications shape to a workflow.

Procedure

Perform the following steps to enable push notifications in an iOS native mobile app project that uses the Connect SDK.

  1. Open the Xcode project for your mobile app.
  2. Add the UserNotifications and ConnectSDK framework import statements to the AppDelegate.swift file:
    import UserNotifications
    ​import ConnectSDK
    
  3. To register for push notifications in a standard way, add the following code to the AppDelegate class:
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .alert, .badge]) { granted, error in
            if granted {
                DispatchQueue.main.async {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        }
        return true
    ​}
  4. To obtain a device token from the APNS server and register for push notifications on your instance of Pega Platform, add the following code to the AppDelegate class:
    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
        NSLog("application:didRegisterForRemoteNotificationsWithDeviceToken: \(deviceTokenString)")
    ​
        let pushRegisterURL = URL(string: "http://sample.pega.com:8080/prweb")!
        PegaApi.shared.authenticationService.registerPushNotification(serverURL: pushRegisterURL, user: "test.user", password: "password", deviceToken: deviceToken) { error in
            if let error = error {
                NSLog("Login error: \(error.localizedDescription)")
                return
            }
            NSLog("Registered")
            // ...
        }
    ​}
    ​
    ​func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        NSLog("application:didFailToRegisterForRemoteNotificationsWithError: \(error.localizedDescription)")
    ​}
  5. To receive remote push notifications, add the following code to the AppDelegate class:
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                         fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        self.application(application, didReceiveRemoteNotification: userInfo)
        completionHandler(.newData)
        // ...
    ​}
    ​
    ​func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        // ...
    ​}

Tags

Pega Platform 7.3.1 Pega Mobile Mashup Mobile Pega Express Communications and Media Consumer Services Financial Services Government Healthcare and Life Sciences Insurance Healthcare and Life Sciences Manufacturing Consumer Services Consumer Services

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us