AppDelegate.m 4.94 KB
/**
 * 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"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <PgySDK/PgyManager.h>
#import <PgyUpdate/PgyUpdateManager.h>

@implementation AppDelegate

#pragma mark 创建单例
/**
 *  @author zsq
 *
 *  @brief  创建单例
 *
 *  @return self
 */
+ (instancetype)sharedInstance {
  static id sharedInstance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    sharedInstance = [[self alloc] init];
  });
  return sharedInstance;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//  NSURL *jsCodeLocation;
//
//  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
  
  if(!launchOptions)
  {
    NSLog(@"用户点击app启动");
  }
  
  NSURL *jsCodeLocation;
  
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
#ifdef DEBUG
  
  jsCodeLocation =  [NSURL URLWithString:@"http://192.168.66.68:8081/index.ios.bundle?platform=ios&dev=true"];
  //  jsCodeLocation =  [NSURL URLWithString:@"http://192.168.1.149:8081/index.ios.bundle?platform=ios&dev=true"];
  
#else
  //release 模式
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
  
#endif
  
  //启动基本SDK
  [[PgyManager sharedPgyManager] startManagerWithAppId:@"a8071f84ef516389d414860d8a62c387"];
  //启动更新检查SDK
  [[PgyUpdateManager sharedPgyManager] startManagerWithAppId:@"a8071f84ef516389d414860d8a62c387"];
  [[PgyUpdateManager sharedPgyManager] checkUpdate];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"metroApp"
                                               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)applicationDidEnterBackground:(UIApplication *)application{
  
  UIApplication*   app = [UIApplication sharedApplication];
  __block    UIBackgroundTaskIdentifier bgTask;
  bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
    dispatch_async(dispatch_get_main_queue(), ^{
      if (bgTask != UIBackgroundTaskInvalid)
      {
        bgTask = UIBackgroundTaskInvalid;
      }
    });
  }];
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    dispatch_async(dispatch_get_main_queue(), ^{
      if (bgTask != UIBackgroundTaskInvalid)
      {
        bgTask = UIBackgroundTaskInvalid;
      }
    });
  });
} 

#pragma mark - app之间通讯的唤起操作
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{

  if ([[NSString stringWithFormat:@"%@",url] containsString:@"shpadtcomcn"]) {
    NSString *str = [[NSString stringWithFormat:@"%@",url] substringFromIndex:[[NSString stringWithFormat:@"%@",url] rangeOfString:@"mobilePhone="].location+12];
    
    NSString *strend = [str substringToIndex:[str rangeOfString:@"from="].location];
    
    [AppDelegate sharedInstance].str_phone = strend;
  }

  
  NSLog(@"URL scheme:%@", [url scheme]);
  NSLog(@"URL query: %@11111111111111111111111111", [url query]);
  return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options
{
  
//  NSString *str = [[NSString stringWithFormat:@"%@",url] substringFromIndex:[[NSString stringWithFormat:@"%@",url] rangeOfString:@"mobilePhone="].location+12];
//
//  NSString *strend = [str substringToIndex:[str rangeOfString:@"from="].location];
//
//  [AppDelegate sharedInstance].str_phone = strend;
  
  if ([[NSString stringWithFormat:@"%@",url] containsString:@"shpadtcomcn"]) {
    NSString *str = [[NSString stringWithFormat:@"%@",url] substringFromIndex:[[NSString stringWithFormat:@"%@",url] rangeOfString:@"mobilePhone="].location+12];
    
    NSString *strend = [str substringToIndex:[str rangeOfString:@"from="].location];
    
    [AppDelegate sharedInstance].str_phone = strend;
  }
  
  NSLog(@"Calling Application Bundle ID: %@", options);
  NSLog(@"URL scheme:%@", [url scheme]);
  NSLog(@"URL query: %@11111111111111111111111111", [url query]);
  return YES;
}



@end