Skip to content

Commit 9fbb9be

Browse files
authored
Merge pull request #73 from twopt/master
updates to README.md
2 parents d0426dc + 70dd394 commit 9fbb9be

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,33 @@ React Native Push Notification API for iOS.
1111

1212
### Install
1313

14-
```
14+
```bash
1515
yarn add @react-native-community/push-notification-ios
1616
```
1717

1818
### Link
19+
1920
There are a couple of cases for linking. Choose the appropriate one.
21+
2022
- `react-native >= 0.60`
2123

2224
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:
23-
```
25+
26+
```bash
2427
cd ios && pod install
2528
```
2629

2730
- `react-native <= 0.59`
28-
```
31+
32+
```bash
2933
react-native link @react-native-community/push-notification-ios
3034
```
3135

3236
- upgrading to `react-native >= 0.60`
3337

3438
First, unlink the library. Then follow the instructions above.
35-
```
39+
40+
```bash
3641
react-native unlink @react-native-community/push-notification-ios
3742
```
3843

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

4752
At the top of the file:
48-
```
53+
54+
```objective-c
4955
#import <RNCPushNotificationIOS.h>
5056
```
57+
5158
Then, add the following lines:
59+
5260
```objective-c
5361
// Required to register for notifications
5462
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
@@ -78,7 +86,32 @@ fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
7886
}
7987
```
8088

89+
Also, if not already present, at the top of the file:
90+
91+
```objective-c
92+
#import <UserNotifications/UserNotifications.h>
93+
```
94+
95+
Inside didFinishLaunchingWithOptions or equivalent:
96+
97+
```objective-c
98+
// Define UNUserNotificationCenter
99+
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
100+
center.delegate = self;
101+
```
102+
103+
And at the bottom (before @end):
104+
105+
```objective-c
106+
// Called when a notification is delivered to a foreground app.
107+
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
108+
{
109+
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
110+
}
111+
```
112+
81113
## Migrating from the core `react-native` module
114+
82115
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:
83116
84117
```js
@@ -98,4 +131,4 @@ import PushNotificationIOS from "@react-native-community/push-notification-ios";
98131
[license-badge]: https://img.shields.io/npm/l/@react-native-community/push-notification-ios.svg?style=flat-square
99132
[license]: https://opensource.org/licenses/MIT
100133
[lean-core-badge]: https://img.shields.io/badge/Lean%20Core-Extracted-brightgreen.svg?style=flat-square
101-
[lean-core-issue]: https://github.com/facebook/react-native/issues/23313
134+
[lean-core-issue]: https://github.com/facebook/react-native/issues/23313

0 commit comments

Comments
 (0)