AppDelegate.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. @interface AppDelegate ()
  10. //@property (nonatomic, strong, readonly) UIWindow *window;
  11. @end
  12. @implementation AppDelegate
  13. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  14. // Override point for customization after application launch.
  15. self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
  16. AS_TabBarViewController *tab = [[AS_TabBarViewController alloc] init];
  17. tab.selectedIndex = 1;
  18. self.window.rootViewController = tab;
  19. [self.window makeKeyAndVisible];
  20. return YES;
  21. }
  22. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  23. NSLog(@"--------userInfo:%@",userInfo);
  24. // completionHandler(UIBackgroundFetchResultNewData);
  25. [self handlePush:userInfo];
  26. }
  27. #pragma mark - dealwith push data
  28. /// 处理来自远程的推送内容
  29. - (void)handlePush:(NSDictionary *)payLoad {
  30. if (payLoad == nil) {
  31. return;
  32. }
  33. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  34. if (aps == nil) {
  35. return;
  36. }
  37. UIApplication *application = [UIApplication sharedApplication];
  38. // 当前 APP 在前台
  39. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  40. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  41. NSLog(@"payLoad=%@",payLoad);
  42. // [self handlePushAction:payLoad]; // 处理推送消息
  43. } else {
  44. [self handlePushAction:payLoad]; // 处理推送消息
  45. }
  46. }
  47. - (void)handlePushAction:(NSDictionary *)payLoad {
  48. NSDictionary *customData = payLoad[@"custom"][@"a"];
  49. NSString *title = customData[@"title"];
  50. NSString *push_para = customData[@"push_para"];
  51. NSString *message_id = customData[@"message_id"];
  52. NSNumber *push_type = customData[@"push_type"];
  53. if (!push_type) {
  54. return;
  55. }
  56. NSInteger type = push_type.integerValue;
  57. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  58. }
  59. @end