Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@ React Native Push Notification API for iOS.

### Install

```
```bash
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](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) when building the app. All you need to do is:
```

```bash
cd ios && pod install
```

- `react-native <= 0.59`
```

```bash
react-native link @react-native-community/push-notification-ios
```

- upgrading to `react-native >= 0.60`

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

```bash
react-native unlink @react-native-community/push-notification-ios
```

Expand All @@ -45,10 +50,13 @@ react-native link @react-native-community/push-notification-ios
Finally, to enable support for `notification` and `register` events you need to augment your AppDelegate.

At the top of the file:
```

```objective-c
#import <RNCPushNotificationIOS.h>
```

Then, add the following lines:

```objective-c
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
Expand Down Expand Up @@ -78,7 +86,32 @@ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
}
```

Also, if not already present, at the top of the file:

```objective-c
#import <UserNotifications/UserNotifications.h>
```

Inside didFinishLaunchingWithOptions or equivalent:

```objective-c
// Define UNUserNotificationCenter
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
```

And at the bottom (before @end):

```objective-c
// Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
```

## 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:

```js
Expand All @@ -98,4 +131,4 @@ import PushNotificationIOS from "@react-native-community/push-notification-ios";
[license-badge]: https://img.shields.io/npm/l/@react-native-community/push-notification-ios.svg?style=flat-square
[license]: https://opensource.org/licenses/MIT
[lean-core-badge]: https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg?style=flat-square
[lean-core-issue]: https://github.com/facebook/react-native/issues/23313
[lean-core-issue]: https://github.com/facebook/react-native/issues/23313