AppDelegate.m 3.41 KB
Newer Older
Lidan Hifi's avatar
Lidan Hifi committed
1 2 3 4 5 6 7 8 9 10
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"
11 12

#import "RCTBundleURLProvider.h"
Lidan Hifi's avatar
Lidan Hifi committed
13
#import "RCTRootView.h"
Lidan Hifi's avatar
Lidan Hifi committed
14
#import "RNNotifications.h"
15
#import "RNNRouter.h"
16 17
#import <PushKit/PushKit.h>

Lidan Hifi's avatar
Lidan Hifi committed
18 19 20 21 22
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;
23
  
24
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
25
  
Lidan Hifi's avatar
Lidan Hifi committed
26
  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
Lidan Hifi's avatar
Lidan Hifi committed
27
                                                      moduleName:@"NotificationsExampleApp"
Lidan Hifi's avatar
Lidan Hifi committed
28 29
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
30
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
31
  
Lidan Hifi's avatar
Lidan Hifi committed
32 33 34 35 36
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
37 38
  [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  
Lidan Hifi's avatar
Lidan Hifi committed
39 40 41
  return YES;
}

42 43 44
// PushKit API Example
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
45
  [[RNNRouter sharedInstance] didUpdatePushCredentials:credentials forType:type];
46 47 48 49
}

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
50
  [[RNNRouter sharedInstance] application:nil didReceiveRemoteNotification:payload.dictionaryPayload fetchCompletionHandler:nil];
51 52
}

53
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
Lidan Hifi's avatar
Lidan Hifi committed
54
{
55
  [[RNNRouter sharedInstance] application:application didFailToRegisterForRemoteNotificationsWithError:error];
Lidan Hifi's avatar
Lidan Hifi committed
56
}
57

Lidan Hifi's avatar
Lidan Hifi committed
58 59
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
60
  [[RNNRouter sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
Lidan Hifi's avatar
Lidan Hifi committed
61 62 63
}

// Required for the notification event.
64
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)notification
Lidan Hifi's avatar
Lidan Hifi committed
65
{
66
  [[RNNRouter sharedInstance] application:application didReceiveRemoteNotification:notification fetchCompletionHandler:nil];
Lidan Hifi's avatar
Lidan Hifi committed
67 68
}

69
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
70
{
71
  [[RNNRouter sharedInstance] userNotificationCenter:center willPresentNotification:notification withCompletionHandler:completionHandler];
72 73
}

74
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
75
{
76
  [[RNNRouter sharedInstance] userNotificationCenter:center didReceiveNotificationResponse:response withCompletionHandler:completionHandler];
77 78
}

Lidan Hifi's avatar
Lidan Hifi committed
79
@end