Newer Version Available

This content describes an older version of this product. View Latest

Enable Push Notifications in a Salesforce Mobile SDK iOS App

Salesforce Mobile SDK for iOS provides the SFPushNotificationManager class to handle push registration. To use it, import <SalesforceSDKCore/SFPushNotificationManager>. The SFPushNotificationManager class is available as a runtime singleton:

This class implements four registration methods:
Mobile SDK calls registerForSalesforceNotifications after login and unregisterSalesforceNotifications at logout. You call the other two methods from your AppDelegate class.
  1. Register with Apple for push notifications by calling registerForRemoteNotifications. Place the call in the application:didFinishLaunchingWithOptions: method.

    If registration succeeds, Apple passes a device token to the application:didRegisterForRemoteNotificationsWithDeviceToken: method of your AppDelegate class.

  2. Forward the device token from Apple to SFPushNotificationManager by calling didRegisterForRemoteNotificationsWithDeviceToken on the SFPushNotificationManager shared instance.
  3. Register to receive Salesforce notifications through the connected app by calling registerForSalesforceNotifications. Make this call only if the access token for the current session is valid.

    Behind the scenes, Mobile SDK automatically reads this value and uses it to register the device against the Salesforce connected app. Each time the user re-opens the app, Mobile SDK automatically renews the registration. This validation allows Salesforce to send notifications to the connected app.

    A device becomes unregistered if:

    The app goes unused for an extended period of time

    OR

    The user logs out of the app

    Note

  4. Add the following method to log an error if registration with Apple fails.