Working with push messages in iOS

This page details the steps needed in order to work with push messages in iOS:

  1. Enable Push Notifications: Go to your Project Navigator’s capabilities tab. Select Push Notifications > Enable.
  1. Create the APNs certificates for your test and production environments. Refer to: Local and Remote Notifications Overview.

  2. Upload the APNs certificates to the PingOne web portal under your app settings. Go to Applications > PingID SDK Applications.

    • Verify that push notifications are working with the above certificates before uploading them to the web portal.
  3. Enable PingID SDK to send silent notifications when needed:

    • Go to your Project Navigator’s capabilities tab.
    • Select Background Mode > Enable.
    • Check Remote notifications.
  4. Register Push: In order to receive push notifications from PingID SDK, use the following code in your didRegisterForRemoteNotificationsWithDeviceToken call:

    + (void)setRemoteNotificationsDeviceToken:(nullable NSData *)deviceToken;

    using the actual deviceToken string, without spaces and brackets.

  5. Handling Push Notifications: PingID SDK will only handle push notifications which were issued by the PingID SDK server. Inside the following method:

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;


    + (BOOL)isRemoteNotificationFromPingID:(nonnull NSDictionary *)userInfo;

    with the userInfo NSDictionary. If the notification is not from PingID SDK, it will not be handled.

    If the push was received from PingID SDK, pass the userInfo to:

    + (void)handleRemoteNotification:(nonnull NSDictionary *)userInfo  
                               completion:(nullable void(^)(PIDRemoteNotificationType  
             remoteNotificationType, NSArray * _Nullable availableTrustLevels, NSDictionary * _Nullable  
             sessionInfo, NSError * _Nullable error))completionBlock

    and handle the response accordingly.

    Please note that the handleRemoteNotification method doesn’t handle didReceiveRemoteNotification:fetchCompletionHandler:, and it should be added to your code.

  6. Push Notifications Categories: PingID SDK uses categories for different notifications. If your app already uses categories, you will need to retrieve the PingID SDK categories NSMutableSet, by calling:

    + (nonnull NSMutableSet *)getPingIDRemoteNotificationsCategories;

    and add that to your current categories.

    • iOS 8 and 9:

      NSMutableSet *categories = [PingID getPingIDDeprecatedRemoteNotificationsCategories];
      UIUserNotificationSettings *settings = [UIUserNotificationSettings
              settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |
              UIUserNotificationTypeSound categories:categories];
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
    • iOS 10 and up: (UNUserNotification support):

      UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
              center.delegate = self;
              [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
                      // Registering UNNotificationCategory more than once results in previous categories being overwritten. PingID provides the needed categories. The developer may add categories.
                      NSMutableSet *categories = [PingID getPingIDRemoteNotificationsCategories];
                      [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories];
                      [[UIApplication sharedApplication] registerForRemoteNotifications];
  7. Cancel Authentication:

    The handleRemoteNotification:completion method provides a mechanism for your application to take action on authentication cancelation events, by returning PIDRemoteNotificationTypeCancel.

  8. Localization: The following keys are returned by the PingID SDK Remote Notification, with suggested localization:

    "notification_confirm" = "Approve";
    "notification_deny" = "Deny";
    "notification.message" = "You have a new authentication request.";
    "notification.title" = "New Authentication";