AppDelegate.m 8.2 KB

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