Created
July 12, 2018 21:48
-
-
Save blueberry404/20d0bfa11fca2d889b002def632e6ca0 to your computer and use it in GitHub Desktop.
AppDelegate file - React Native Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <UserNotifications/UserNotifications.h> | |
@interface AppDelegate : UIResponder <UIApplicationDelegate, UNUserNotificationCenterDelegate> | |
@property (nonatomic, strong) UIWindow *window; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "AppDelegate.h" | |
#import <Firebase.h> | |
#import "RNFirebaseNotifications.h" | |
#import "RNFirebaseMessaging.h" | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSURL *jsCodeLocation; | |
//Add these 3 lines | |
[FIRApp configure]; | |
[[UNUserNotificationCenter currentNotificationCenter] setDelegate:self]; | |
[RNFirebaseNotifications configure]; | |
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation | |
moduleName:@"agiledefense" | |
initialProperties:nil | |
launchOptions:launchOptions]; | |
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; | |
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | |
UIViewController *rootViewController = [UIViewController new]; | |
rootViewController.view = rootView; | |
self.window.rootViewController = rootViewController; | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(nonnull NSDictionary *)userInfo | |
fetchCompletionHandler:(nonnull void (^)(UIBackgroundFetchResult))completionHandler{ | |
[[RNFirebaseNotifications instance] didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; | |
} | |
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { | |
[[RNFirebaseMessaging instance] didRegisterUserNotificationSettings:notificationSettings]; | |
} | |
-(void) userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { | |
[[RNFirebaseMessaging instance] didReceiveRemoteNotification:response.notification.request.content.userInfo]; | |
completionHandler(); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment