AppDelegate.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. [self.window makeKeyAndVisible];
  32. return YES;
  33. }
  34. -(void)xxx_ytkNetConfig{
  35. YTKNetworkAgent *agent = [YTKNetworkAgent sharedAgent];
  36. [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"];
  37. YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
  38. config.securityPolicy.allowInvalidCertificates = YES;
  39. config.securityPolicy.validatesDomainName = NO;
  40. config.baseUrl = [NSString stringWithFormat:@"%@",AS_Server];
  41. NSLog(@"baseUrl-----%@",config.baseUrl)
  42. }
  43. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  44. NSLog(@"--------userInfo:%@",userInfo);
  45. // completionHandler(UIBackgroundFetchResultNewData);
  46. [self handlePush:userInfo];
  47. }
  48. #pragma mark - dealwith push data
  49. /// 处理来自远程的推送内容
  50. - (void)handlePush:(NSDictionary *)payLoad {
  51. if (payLoad == nil) {
  52. return;
  53. }
  54. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  55. if (aps == nil) {
  56. return;
  57. }
  58. UIApplication *application = [UIApplication sharedApplication];
  59. // 当前 APP 在前台
  60. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  61. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  62. NSLog(@"payLoad=%@",payLoad);
  63. // [self handlePushAction:payLoad]; // 处理推送消息
  64. } else {
  65. [self handlePushAction:payLoad]; // 处理推送消息
  66. }
  67. }
  68. - (void)handlePushAction:(NSDictionary *)payLoad {
  69. NSDictionary *customData = payLoad[@"custom"][@"a"];
  70. NSString *title = customData[@"title"];
  71. NSString *push_para = customData[@"push_para"];
  72. NSString *message_id = customData[@"message_id"];
  73. NSNumber *push_type = customData[@"push_type"];
  74. if (!push_type) {
  75. return;
  76. }
  77. NSInteger type = push_type.integerValue;
  78. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  79. }
  80. @end