AppDelegate.m 3.6 KB

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