Created
January 8, 2017 17:36
-
-
Save LeoLeBras/8240f873d05ba8efdb52618bc2421e73 to your computer and use it in GitHub Desktop.
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 "RCTUtils.h" | |
#import <React/RCTBundleURLProvider.h> | |
#import <React/RCTRootView.h> | |
#import <FBSDKCoreKit/FBSDKCoreKit.h> | |
#import <FBSDKLoginKit/FBSDKLoginKit.h> | |
@implementation AppDelegate | |
- (void)applicationDidBecomeActive:(UIApplication *)application { | |
[FBSDKAppEvents activateApp]; | |
} | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
NSURL *jsCodeLocation; | |
[[FBSDKApplicationDelegate sharedInstance] application:application | |
didFinishLaunchingWithOptions:launchOptions]; | |
#if DEBUG | |
#if TARGET_IPHONE_SIMULATOR | |
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"]; | |
#else | |
jsCodeLocation = [NSURL URLWithString:@"http://x.x.x.x:8081/index.ios.bundle"]; | |
#endif | |
#else | |
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; | |
#endif | |
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation | |
moduleName:@"Wino" | |
initialProperties:nil | |
launchOptions:launchOptions]; | |
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | | |
UIUserNotificationTypeBadge | | |
UIUserNotificationTypeSound); | |
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes | |
categories:nil]; | |
[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; | |
[[UIApplication sharedApplication] registerForRemoteNotifications]; | |
// Get launch image | |
NSString *launchImageName = nil; | |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { | |
CGFloat height = MAX(RCTScreenSize().width, RCTScreenSize().height); | |
if (height == 480) launchImageName = @"LaunchImage-700@2x.png"; // iPhone 4/4s | |
else if (height == 568) launchImageName = @"LaunchImage-700-568h@2x.png"; // iPhone 5/5s | |
else if (height == 667) launchImageName = @"LaunchImage-800-667h@2x.png"; // iPhone 6 | |
else if (height == 736) launchImageName = @"LaunchImage-800-Portrait-736h@3x.png"; // iPhone 6+ | |
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { | |
CGFloat scale = RCTScreenScale(); | |
if (scale == 1) launchImageName = @"LaunchImage-700-Portrait~ipad.png"; // iPad | |
else if (scale == 2) launchImageName = @"LaunchImage-700-Portrait@2x~ipad.png"; // Retina iPad | |
} | |
// Create loading view | |
UIImage *image = [UIImage imageNamed:launchImageName]; | |
if (image) { | |
UIImageView *imageView = [[UIImageView alloc] initWithFrame:(CGRect){CGPointZero, RCTScreenSize()}]; | |
imageView.contentMode = UIViewContentModeBottom; | |
imageView.image = image; | |
rootView.loadingView = imageView; | |
} | |
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 didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { | |
[FBSDKAppEvents setPushNotificationsDeviceToken:deviceToken]; | |
} | |
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { | |
[FBSDKAppEvents logPushNotificationOpen:userInfo]; | |
} | |
- (void)application:(UIApplication *)application | |
handleActionWithIdentifier:(NSString *)identifier | |
forRemoteNotification:(NSDictionary *)userInfo | |
completionHandler:(void (^)())completionHandler { | |
[FBSDKAppEvents logPushNotificationOpen:userInfo action:identifier]; | |
} | |
- (BOOL)application:(UIApplication *)application | |
openURL:(NSURL *)url | |
sourceApplication:(NSString *)sourceApplication | |
annotation:(id)annotation { | |
return [[FBSDKApplicationDelegate sharedInstance] application:application | |
openURL:url | |
sourceApplication:sourceApplication | |
annotation:annotation]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment