AppDelegate.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <PayPal-iOS-SDK/PayPalMobile.h>
  11. @interface AppDelegate ()
  12. //@property (nonatomic, strong, readonly) UIWindow *window;
  13. @end
  14. @implementation AppDelegate
  15. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  16. // Override point for customization after application launch.
  17. if (@available(iOS 15.0, *)) {
  18. UITableView.appearance.sectionHeaderTopPadding = 0;
  19. } else {
  20. // Fallback on earlier versions
  21. }
  22. // 设置PayPal环境,可以是 sandbox 或 live
  23. [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction:@"AT88L7L2ZI0mUNNamuY6VRVtuH8Fik6kUrKC-0HtIEpC79wJA56U8Il9iC-FJKXUtxoGkbn7DtdE8skD",PayPalEnvironmentSandbox:@"ASThYYeLhhglcED1R5LrwwjNLpyLYA5yp_8tHTYimlhojmKeC3_FFD2wS2fQp-LlfQalgJFawbEAA5Bu"}];
  24. [ASCurrencyManager.shared getAllCurrencyData];
  25. // [self xxx_ytkNetConfig];
  26. [PPNetworkHelper openLog];
  27. self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
  28. AS_TabBarViewController *tab = [[AS_TabBarViewController alloc] init];
  29. tab.selectedIndex = 0;
  30. self.window.rootViewController = tab;
  31. if (ASUserInfoManager.shared.isLogin ) {
  32. [ASUserInfoManager.shared getInfo];
  33. }
  34. [ASNetTools reqNet_getAdvCoupons];
  35. [self.window makeKeyAndVisible];
  36. return YES;
  37. }
  38. -(void)xxx_ytkNetConfig{
  39. YTKNetworkAgent *agent = [YTKNetworkAgent sharedAgent];
  40. [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"];
  41. YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
  42. config.securityPolicy.allowInvalidCertificates = YES;
  43. config.securityPolicy.validatesDomainName = NO;
  44. config.baseUrl = [NSString stringWithFormat:@"%@",AS_Server];
  45. NSLog(@"baseUrl-----%@",config.baseUrl)
  46. }
  47. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  48. NSLog(@"--------userInfo:%@",userInfo);
  49. // completionHandler(UIBackgroundFetchResultNewData);
  50. [self handlePush:userInfo];
  51. }
  52. #pragma mark - dealwith push data
  53. /// 处理来自远程的推送内容
  54. - (void)handlePush:(NSDictionary *)payLoad {
  55. if (payLoad == nil) {
  56. return;
  57. }
  58. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  59. if (aps == nil) {
  60. return;
  61. }
  62. UIApplication *application = [UIApplication sharedApplication];
  63. // 当前 APP 在前台
  64. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  65. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  66. NSLog(@"payLoad=%@",payLoad);
  67. // [self handlePushAction:payLoad]; // 处理推送消息
  68. } else {
  69. [self handlePushAction:payLoad]; // 处理推送消息
  70. }
  71. }
  72. - (void)handlePushAction:(NSDictionary *)payLoad {
  73. NSDictionary *customData = payLoad[@"custom"][@"a"];
  74. NSString *title = customData[@"title"];
  75. NSString *push_para = customData[@"push_para"];
  76. NSString *message_id = customData[@"message_id"];
  77. NSNumber *push_type = customData[@"push_type"];
  78. if (!push_type) {
  79. return;
  80. }
  81. NSInteger type = push_type.integerValue;
  82. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  83. }
  84. @end