mirror of
https://github.com/zhigang1992/react-native-notifications.git
synced 2026-06-15 02:19:23 +08:00
50 lines
1.5 KiB
Markdown
Executable File
50 lines
1.5 KiB
Markdown
Executable File
---
|
|
id: installation-ios
|
|
title: iOS Installation
|
|
sidebar_label: iOS Installation
|
|
---
|
|
|
|
As with any React Native project, the first step is to add the project as an npm dependency.
|
|
|
|
The 2nd is to do some platform specific setup so as to be able to work with Apple and Google's services for push notifications.
|
|
|
|
Start by running this:
|
|
|
|
```
|
|
$ npm install react-native-notifications --save
|
|
```
|
|
|
|
|
|
Then, [Manually link](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#manual-linking) the library to your Xcode project.
|
|
|
|
|
|
To enable notifications support add the following line at the top of your `AppDelegate.m`
|
|
|
|
```objective-c
|
|
#import "RNNotifications.h"
|
|
```
|
|
|
|
Start monitor notifications in: `application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions`
|
|
|
|
```objective-c
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
[RNNotifications startMonitorNotifications]; // -> Add this line
|
|
|
|
return YES;
|
|
}
|
|
|
|
```
|
|
|
|
|
|
And add the following methods to support registration:
|
|
|
|
```objective-c
|
|
|
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
[RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
|
|
}
|
|
|
|
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
|
|
[RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
|
|
} |