Files
notesnook/apps/mobile/ios/Notesnook/AppDelegate.m

125 lines
4.1 KiB
Mathematica
Raw Normal View History

2019-11-15 01:17:59 +05:00
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
2022-01-22 09:32:12 +05:00
#import "RNBootSplash.h"
2020-11-07 13:15:58 +05:00
#import <React/RCTLinkingManager.h>
2020-11-23 11:25:51 +05:00
#import <MMKV.h>
2020-04-09 13:02:37 +05:00
@implementation AppDelegate
2021-02-25 02:43:54 +05:00
UINavigationController *navController;
UIViewController *rootViewController;
UIViewController *shareViewController;
RCTBridge *bridge;
2019-11-15 01:17:59 +05:00
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
2021-02-25 02:43:54 +05:00
shareViewController = [UIViewController new];
NSURL *url = (NSURL *) [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if (url != nil) {
navController = [[UINavigationController alloc] initWithRootViewController:shareViewController];
2021-04-07 10:49:42 +05:00
} else {
2021-02-25 02:43:54 +05:00
rootViewController = [UIViewController new];
navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
2021-04-07 10:49:42 +05:00
}
2021-02-25 02:43:54 +05:00
navController.navigationBarHidden = YES;
bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
if (url != nil) {
RCTRootView *shareView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"QuickNoteIOS"
initialProperties:nil];
shareView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
shareViewController.view = shareView;
} else {
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"Notesnook" initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
rootViewController.view = rootView;
}
2019-11-15 01:17:59 +05:00
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
2021-02-25 02:43:54 +05:00
self.window.rootViewController = navController;
2019-11-15 01:17:59 +05:00
[self.window makeKeyAndVisible];
2022-01-22 09:32:12 +05:00
[RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView];
2020-10-29 12:23:13 +05:00
2019-11-15 01:17:59 +05:00
return YES;
}
2020-11-23 11:25:51 +05:00
- (void)applicationWillTerminate:(UIApplication *)application {
2021-01-17 12:52:23 +05:00
MMKV *kv = [MMKV mmkvWithID:@"default" mode:MMKVMultiProcess];
2020-11-23 11:25:51 +05:00
[kv removeValueForKey:@"appState"];
}
2020-11-07 13:15:58 +05:00
2019-11-15 01:17:59 +05:00
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
2021-04-07 08:01:33 +05:00
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
return [RCTLinkingManager application:application
continueUserActivity:userActivity
restorationHandler:restorationHandler];
}
2020-11-07 13:15:58 +05:00
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
2021-02-25 02:43:54 +05:00
if ([url.absoluteString isEqual:@"ShareMedia://QuickNoteWidget"]) {
if (rootViewController != nil) {
RCTRootView *shareView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"QuickNoteIOS"
initialProperties:nil];
shareView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
shareViewController.view = shareView;
[navController pushViewController:shareViewController animated:false];
}
}
if ([url.absoluteString isEqual:@"ShareMedia://MainApp"]) {
if (rootViewController == nil) {
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:1.0];
exit(0);
} else {
UIApplication *app = [UIApplication sharedApplication];
[app performSelector:@selector(suspend)];
[NSThread sleepForTimeInterval:0.5];
[navController popToRootViewControllerAnimated:false];
}
}
2020-11-07 13:15:58 +05:00
return [RCTLinkingManager application:application openURL:url options:options];
}
2019-11-15 01:17:59 +05:00
@end