AppDelegate.m 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // AppDelegate.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/22.
  6. //
  7. #import "AppDelegate.h"
  8. #import "ASTabBarController.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. ASTabBarController *tab = [[ASTabBarController alloc] init];
  17. self.window.rootViewController = tab;
  18. [self.window makeKeyAndVisible];
  19. return YES;
  20. }
  21. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  22. NSLog(@"--------userInfo:%@",userInfo);
  23. // completionHandler(UIBackgroundFetchResultNewData);
  24. [self handlePush:userInfo];
  25. }
  26. #pragma mark - dealwith push data
  27. /// 处理来自远程的推送内容
  28. - (void)handlePush:(NSDictionary *)payLoad {
  29. if (payLoad == nil) {
  30. return;
  31. }
  32. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  33. if (aps == nil) {
  34. return;
  35. }
  36. UIApplication *application = [UIApplication sharedApplication];
  37. // 当前 APP 在前台
  38. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  39. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  40. NSLog(@"payLoad=%@",payLoad);
  41. // [self handlePushAction:payLoad]; // 处理推送消息
  42. } else {
  43. [self handlePushAction:payLoad]; // 处理推送消息
  44. }
  45. }
  46. - (void)handlePushAction:(NSDictionary *)payLoad {
  47. NSDictionary *customData = payLoad[@"custom"][@"a"];
  48. NSString *title = customData[@"title"];
  49. NSString *push_para = customData[@"push_para"];
  50. NSString *message_id = customData[@"message_id"];
  51. NSNumber *push_type = customData[@"push_type"];
  52. if (!push_type) {
  53. return;
  54. }
  55. NSInteger type = push_type.integerValue;
  56. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  57. }
  58. @end