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