/**
 Push
 Notifications  */

Go back to React Native Getting Started Guide

Push Notifications (React Native - iOS)

6. Enable Remote Notifications in Xcode Project

You can either turn Remote Notifications on either from the Xcode UI or by editing the app's property list (usually Info.plist) file depending on you preference.

Option 1: Using Xcode UI

  • In Xcode, choose View > Navigators > Show Project Navigator, or press ⌘1.
  • Select your target under the TARGET heading and then select the Capabilities tab
  • Open Background Modes, turn on slider to enable Background Modes then turn on Remote Notifications by clicking on the corresponding check mark.

    Remote Notifications

Option 2: Editing app's property list (usually Info.plist) file directly

Open your Info.plist file and add following lines

    <key>UIBackgroundModes</key>
    <array>
      <string>remote-notification</string>
    </array>

7. Enable your app for Push Notifications a.k.a. write code

    Generate a build for iOS before proceeding.

    We will modify the generated app delegate AppDelegate.m in following subsections.

    Register For Remote Notifications

  • Objective-C in React Native Project

    After generating a build for iOS, add following code in your generated app delegate AppDelegate.m file's application: didFinishLaunchingWithOptions: method.

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {    
        // iOS 8.x and tvOS 9.x onwards
        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert 
                                                    | UIUserNotificationTypeBadge 
                                                    | UIUserNotificationTypeSound);
    
        UIUserNotificationSettings *userNotificationSettings = [UIUserNotificationSettings
                                   settingsForTypes:userNotificationTypes categories:nil];
        
        [application registerUserNotificationSettings:userNotificationSettings];
        [application registerForRemoteNotifications];  
    } else { // Fallback for versions earlier than iOS 8.x
        UIRemoteNotificationType remoteNotificationTypes = (UIRemoteNotificationTypeAlert 
                         | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound);
        
        [application registerForRemoteNotificationTypes:remoteNotificationTypes];
    }
    

    Let Pyze know the APNS device token

  • Objective-C in React Native Project

    After generating a build for iOS, add following code in your generated app delegate AppDelegate.m file's application: didRegisterForRemoteNotificationsWithDeviceToken: method.

    -(void) application: (UIApplication *) application 
        didRegisterForRemoteNotificationsWithDeviceToken: (NSData *) deviceToken {
            [Pyze setRemoteNotificationDeviceToken:deviceToken];
    }
    

    Let Pyze process Remote Notifications

  • Objective-C in React Native Project

    After generating a build for iOS, add following code in your generated app delegate AppDelegate.m file's application: didReceiveRemoteNotification: OR application: didReceiveRemoteNotification: fetchCompletionHandler: methods.

    //EITHER
    -(void)application:(UIApplication *)application 
        didReceiveRemoteNotification:(NSDictionary *)userInfo {
            [Pyze processReceivedRemoteNotification:userInfo];
    }
    
    //OR (recommended for background fetch)
    -(void) application:(UIApplication *)application 
        didReceiveRemoteNotification:(NSDictionary *)userInfo 
        fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
            [Pyze processReceivedRemoteNotification:userInfo];
    }
    



See App Store Review Guidelines for Push Notifications

To print, click on expand all sections and use your browser's print function. The images will print in printer-friendly size.


Go back to React Native Developer Center.


About Pyze

Pyze Growth Intelligence® is a transformative SaaS platform that enables mobile and web app businesses to automate engagement, retention and growth of their users. Signup at Pyze, install and initialize the Pyze SDK and watch your app grow.