AppDelegate.m 3.57 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

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 37 38 39
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

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

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{
48
  [RNNotifications didReceiveRemoteNotification:payload.dictionaryPayload];
49 50
}

51 52 53

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
Lidan Hifi's avatar
Lidan Hifi committed
54
{
55
  [RNNotifications didRegisterUserNotificationSettings:notificationSettings];
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
  [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
Lidan Hifi's avatar
Lidan Hifi committed
61 62
}

63

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

// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
Lidan Hifi's avatar
Lidan Hifi committed
71
{
72
  [RNNotifications didReceiveLocalNotification:notification];
Lidan Hifi's avatar
Lidan Hifi committed
73 74
}

75 76 77

// Required for the notification actions.
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
78
{
79
  [RNNotifications handleActionWithIdentifier:identifier forLocalNotification:notification withResponseInfo:responseInfo completionHandler:completionHandler];
80 81
}

82
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler
83
{
84
  [RNNotifications handleActionWithIdentifier:identifier forRemoteNotification:userInfo withResponseInfo:responseInfo completionHandler:completionHandler];
85 86
}

Lidan Hifi's avatar
Lidan Hifi committed
87
@end