AppDelegate.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // AppDelegate.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/22.
  6. //
  7. #import "AppDelegate.h"
  8. #import "AS_TabBarViewController.h"
  9. #import <YTKNetwork/YTKNetwork.h>
  10. #import <FBSDKLoginKit/FBSDKLoginKit.h>
  11. #import <StripeCore/StripeCore-Swift.h>
  12. #import <OneSignal/OneSignal.h>
  13. #import "ASPushOneSignalManager.h"
  14. @import Stripe;
  15. @interface AppDelegate ()<UNUserNotificationCenterDelegate>
  16. //@property (nonatomic, strong, readonly) UIWindow *window;
  17. @end
  18. @implementation AppDelegate
  19. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  20. // Override point for customization after application launch.
  21. if (@available(iOS 15.0, *)) {
  22. UITableView.appearance.sectionHeaderTopPadding = 0;
  23. } else {
  24. // Fallback on earlier versions
  25. }
  26. [ASCurrencyManager.shared getAllCurrencyData];
  27. [ASNetTools reqNet_getAdvCoupons];
  28. // [self xxx_ytkNetConfig];
  29. [PPNetworkHelper openLog];
  30. self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
  31. AS_TabBarViewController *tab = [[AS_TabBarViewController alloc] init];
  32. tab.selectedIndex = 0;
  33. self.window.rootViewController = tab;
  34. if (ASUserInfoManager.shared.isLogin ) {
  35. [ASUserInfoManager.shared getInfo];
  36. }
  37. [self.window makeKeyAndVisible];
  38. //StripeAPI
  39. [StripeAPI setDefaultPublishableKey:StripePublishableKey];
  40. // 为了使用 Facebook SDK 应该调用如下方法
  41. [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  42. // 注册 FacebookAppID
  43. [[FBSDKSettings sharedSettings] setAppID:Facebook_AppID];
  44. //推送相关配置
  45. [self oneSignalPushConfig:launchOptions];
  46. [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  47. [self pushAuthRequest];
  48. // [OneSignal sendTag:@"SufixUid" value:@"-"];
  49. // [self updateUserData];
  50. return YES;
  51. }
  52. -(void)xxx_ytkNetConfig{
  53. YTKNetworkAgent *agent = [YTKNetworkAgent sharedAgent];
  54. [agent setValue:[NSSet setWithObjects:@"application/json", @"text/html", @"text/json", @"text/plain", @"text/javascript", @"text/xml", @"image/*",@"image/jpeg",@"image/jpg",@"image/png",@"application/x-javascript",nil] forKeyPath:@"_manager.responseSerializer.acceptableContentTypes"];
  55. YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
  56. config.securityPolicy.allowInvalidCertificates = YES;
  57. config.securityPolicy.validatesDomainName = NO;
  58. config.baseUrl = [NSString stringWithFormat:@"%@",AS_Server];
  59. NSLog(@"baseUrl-----%@",config.baseUrl)
  60. }
  61. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  62. NSLog(@"--------userInfo:%@",userInfo);
  63. // completionHandler(UIBackgroundFetchResultNewData);
  64. [self handlePush:userInfo];
  65. }
  66. #pragma mark - dealwith push data
  67. /// 处理来自远程的推送内容
  68. - (void)handlePush:(NSDictionary *)payLoad {
  69. if (payLoad == nil) {
  70. return;
  71. }
  72. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  73. if (aps == nil) {
  74. return;
  75. }
  76. UIApplication *application = [UIApplication sharedApplication];
  77. // 当前 APP 在前台
  78. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  79. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  80. NSLog(@"payLoad=%@",payLoad);
  81. // [self handlePushAction:payLoad]; // 处理推送消息
  82. } else {
  83. [self handlePushAction:payLoad]; // 处理推送消息
  84. }
  85. }
  86. - (void)handlePushAction:(NSDictionary *)payLoad {
  87. NSDictionary *customData = payLoad[@"custom"][@"a"];
  88. NSString *title = customData[@"title"];
  89. NSString *push_para = customData[@"push_para"];
  90. NSString *message_id = customData[@"message_id"];
  91. NSNumber *push_type = customData[@"push_type"];
  92. if (!push_type) {
  93. return;
  94. }
  95. NSInteger type = push_type.integerValue;
  96. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  97. }
  98. #pragma mark - **************** applicationDelegate ****************
  99. - (BOOL)application:(UIApplication *)app
  100. openURL:(NSURL *)url
  101. options:(NSDictionary *)options {
  102. [[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options];
  103. // nzk Google Signin
  104. BOOL stripeHandled = [StripeAPI handleStripeURLCallbackWithURL:url];
  105. if(stripeHandled){
  106. return YES;
  107. }
  108. // nzk Google Signin end
  109. return YES;
  110. }
  111. - (void)pushAuthRequest {
  112. // 申请权限1
  113. [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  114. if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
  115. UNAuthorizationOptions authOptions =
  116. UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  117. [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions
  118. completionHandler:^(BOOL granted, NSError *_Nullable error){
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. [[UIApplication sharedApplication] registerForRemoteNotifications]; //注册获得device Token
  121. });
  122. }];
  123. }
  124. }];
  125. dispatch_async(dispatch_get_main_queue(), ^{
  126. [[UIApplication sharedApplication] registerForRemoteNotifications]; //注册获得device Token
  127. });
  128. }
  129. -(void)oneSignalPushConfig:(NSDictionary *)launchOptions{
  130. /*
  131. //#ifdef DEBUG
  132. // [MobPush setAPNsForProduction:NO];
  133. //#else
  134. // [MobPush setAPNsForProduction:YES];
  135. //#endif
  136. // //设置地区:regionId 默认0(国内),1:海外
  137. // [MobPush setRegionID:1];
  138. // //MobPush推送设置(获得角标、声音、弹框提醒权限)
  139. // MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
  140. // configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
  141. // [MobPush setupNotification:configuration];
  142. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:) name:MobPushDidReceiveMessageNotification object:nil];
  143. */
  144. //初始化OneSignal SDK
  145. [ASOneSignalManager initOneSignalSDKWithPushConfig:launchOptions];
  146. // // Remove this method to stop OneSignal Debugging
  147. // [OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
  148. //
  149. // // OneSignal initialization
  150. // [OneSignal initWithLaunchOptions:launchOptions];
  151. // [OneSignal setAppId:@"618fe580-bc97-4bf4-b2bb-5039f9dbbc82"];
  152. //
  153. // // promptForPushNotifications will show the native iOS notification permission prompt.
  154. // // We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 8)
  155. // [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
  156. // NSLog(@"User accepted notifications: %d", accepted);
  157. // }];
  158. // Set your customer userId
  159. // [OneSignal setExternalUserId:@"userId"];
  160. // Pass in email provided by customer
  161. // [OneSignal setEmail:@"example@domain.com"];
  162. // Pass in phone number provided by customer
  163. // [OneSignal setSMSNumber:@"+11234567890"];
  164. // [OneSignal sendTag:@"key" value:@"value"];
  165. #ifdef DEBUG
  166. [PPNetworkHelper openLog];
  167. #else
  168. [PPNetworkHelper closeLog];
  169. #endif
  170. }
  171. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
  172. // 用户点击了通知
  173. // 通过response参数处理用户的点击事件
  174. completionHandler();
  175. NSDictionary *payLoad = response.notification.request.content.userInfo;
  176. [self handlePushAction:payLoad];
  177. }
  178. @end