AppDelegate.m 3.2 KB

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