Skip to content

laurent22/react-native-push-notification-ios

 
 

Repository files navigation

@react-native-community/push-notification-ios

Build Status Version MIT License Lean Core Badge

React Native Push Notification API for iOS.

Getting started

Install

yarn add @react-native-community/push-notification-ios

Link

There are a couple of cases for linking. Choose the appropriate one.

  • react-native >= 0.60

The package is automatically linked when building the app. All you need to do is:

cd ios && pod install
  • react-native <= 0.59
react-native link @react-native-community/push-notification-ios
  • upgrading to react-native >= 0.60

First, unlink the library. Then follow the instructions above.

react-native unlink @react-native-community/push-notification-ios
  • manual linking

If you don't want to use the methods above, you can always link the library manually.

Update AppDelegate.m

Finally, to enable support for notification and register events you need to augment your AppDelegate.

At the top of the file:

#import <RNCPushNotificationIOS.h>

Then, add the following lines:

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
  [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
  [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
  [RNCPushNotificationIOS didReceiveLocalNotification:notification];
}

Migrating from the core react-native module

This module was created when the PushNotificationIOS was split out from the core of React Native. To migrate to this module you need to follow the installation instructions above and then change you imports from:

import { PushNotificationIOS } from "react-native";

to:

import PushNotificationIOS from "@react-native-community/push-notification-ios";

About

React Native Push Notification API for iOS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 48.5%
  • JavaScript 36.8%
  • Starlark 7.9%
  • Java 5.5%
  • Ruby 1.3%