GithubHelp home page GithubHelp logo

jmyers0022 / react-native-push-notification-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from react-native-push-notification/ios

0.0 1.0 0.0 305 KB

React Native Push Notification API for iOS.

License: MIT License

Java 5.50% JavaScript 36.27% Objective-C 48.93% Ruby 1.30% Starlark 8.00%

react-native-push-notification-ios's Introduction

@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];
}

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

#import <UserNotifications/UserNotifications.h>

Inside didFinishLaunchingWithOptions or equivalent:

  // Define UNUserNotificationCenter
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;

And at the bottom (before @end):

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

import { PushNotificationIOS } from "react-native";

to:

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

react-native-push-notification-ios's People

Contributors

calintamas avatar cpojer avatar dependabot[bot] avatar gp2mv3 avatar ifsnow avatar jsamr avatar laurent22 avatar leonid-shevtsov avatar lucianomlima avatar naturalclar avatar orta avatar plisitza avatar rafaellincoln avatar senne-af avatar thymikee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.