AppDelegate.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // AppDelegate.m
  3. // Demo
  4. //
  5. // Created by Simon on 2019/3/22.
  6. // Copyright © 2019 Simon. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import <IQKeyboardManager/IQKeyboardManager.h>
  10. #import "MTHttpTool.h"
  11. #import <AMapFoundationKit/AMapFoundationKit.h>
  12. #import <AMapLocationKit/AMapLocationKit.h>
  13. #import "WXApi.h"
  14. #import "WXApiManager.h"
  15. #import <AlipaySDK/AlipaySDK.h>
  16. @interface AppDelegate ()<AMapLocationManagerDelegate>
  17. @property (nonatomic, strong) AMapLocationManager *locagionmanager;
  18. @end
  19. @implementation AppDelegate
  20. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  21. //设置主控制器
  22. [self setupRootVC];
  23. //键盘管理
  24. [self configKeyBoard];
  25. //网路监听
  26. [self checkNetWork];
  27. //高德
  28. [AMapServices sharedServices].apiKey = @"7e3a07e5cf949b0c63d055d64ca40e2f";
  29. self.locagionmanager.delegate = self;
  30. [WXApi registerApp:@"wxc6e7176f9e9cb6b5" universalLink:@"https://gujia.hdlkeji.com/"];
  31. return YES;
  32. }
  33. - (void)applicationWillResignActive:(UIApplication *)application {
  34. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
  35. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
  36. }
  37. - (void)applicationDidEnterBackground:(UIApplication *)application {
  38. // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
  39. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  40. }
  41. - (void)applicationWillEnterForeground:(UIApplication *)application {
  42. // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
  43. }
  44. - (void)applicationDidBecomeActive:(UIApplication *)application {
  45. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
  46. }
  47. - (void)applicationWillTerminate:(UIApplication *)application {
  48. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  49. }
  50. #pragma mark -- lazy
  51. -(MTRootController*)rootTabbarVC{
  52. return _rootTabbarVC = [MTRootController new];
  53. }
  54. #pragma mark -- didFinishLaunching
  55. //键盘管理
  56. -(void)configKeyBoard{
  57. [IQKeyboardManager sharedManager].enable = YES;
  58. }
  59. //设置主控制器
  60. -(void)setupRootVC{
  61. // MTLoginViewController *loginVc = [[MTLoginViewController alloc] init];
  62. CustomNavigationController *nav = [[CustomNavigationController alloc] initWithRootViewController:self.rootTabbarVC];
  63. self.window.rootViewController = nav;
  64. }
  65. // 网络监听
  66. -(void)checkNetWork{
  67. MTHttpTool *netTool = [MTHttpTool shareInstance];
  68. [netTool checkNetworkStatus:^(BOOL netUsable) {
  69. NSLog(@"%ld",(long)netTool.netStatus);
  70. }];
  71. }
  72. #pragma mark -- other
  73. -(void)changeLabgue{
  74. [self rootTabbarVC];
  75. }
  76. - (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager
  77. {
  78. [locationManager requestAlwaysAuthorization];
  79. }
  80. -(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
  81. return [WXApi handleOpenURL:url delegate:self];
  82. }
  83. - (BOOL)application:(UIApplication *)application
  84. openURL:(NSURL *)url
  85. options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  86. NSString *str1 = [url absoluteString];
  87. if ([str1 rangeOfString:@"wx"].location != NSNotFound) {
  88. //wechat
  89. return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  90. }
  91. if ([url.host isEqualToString:@"safepay"]) {
  92. // 支付跳转支付宝钱包进行支付,处理支付结果
  93. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  94. [[NSNotificationCenter defaultCenter] postNotificationName:@"kAliPayCallBack" object:resultDic];
  95. }];
  96. }
  97. return true;
  98. }
  99. -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  100. if ([url.host isEqualToString:@"safepay"]) {
  101. // 支付跳转支付宝钱包进行支付,处理支付结果
  102. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  103. [[NSNotificationCenter defaultCenter] postNotificationName:@"kAliPayCallBack" object:resultDic];
  104. }];
  105. }else{
  106. return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];\
  107. }
  108. return true;
  109. }
  110. @end