AppDelegate.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #import <FBSDKLoginKit/FBSDKLoginKit.h>
  11. @interface AppDelegate ()
  12. //@property (nonatomic, strong, readonly) UIWindow *window;
  13. @end
  14. @implementation AppDelegate
  15. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  16. // Override point for customization after application launch.
  17. if (@available(iOS 15.0, *)) {
  18. UITableView.appearance.sectionHeaderTopPadding = 0;
  19. } else {
  20. // Fallback on earlier versions
  21. }
  22. // 为了使用 Facebook SDK 应该调用如下方法
  23. [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  24. // 注册 FacebookAppID
  25. [[FBSDKSettings sharedSettings] setAppID:Facebook_AppID];
  26. [ASCurrencyManager.shared getAllCurrencyData];
  27. // [self xxx_ytkNetConfig];
  28. [PPNetworkHelper openLog];
  29. self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
  30. AS_TabBarViewController *tab = [[AS_TabBarViewController alloc] init];
  31. tab.selectedIndex = 0;
  32. self.window.rootViewController = tab;
  33. if (ASUserInfoManager.shared.isLogin ) {
  34. [ASUserInfoManager.shared getInfo];
  35. }
  36. [ASNetTools reqNet_getAdvCoupons];
  37. [self.window makeKeyAndVisible];
  38. return YES;
  39. }
  40. -(void)xxx_ytkNetConfig{
  41. YTKNetworkAgent *agent = [YTKNetworkAgent sharedAgent];
  42. [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"];
  43. YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
  44. config.securityPolicy.allowInvalidCertificates = YES;
  45. config.securityPolicy.validatesDomainName = NO;
  46. config.baseUrl = [NSString stringWithFormat:@"%@",AS_Server];
  47. NSLog(@"baseUrl-----%@",config.baseUrl)
  48. }
  49. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  50. NSLog(@"--------userInfo:%@",userInfo);
  51. // completionHandler(UIBackgroundFetchResultNewData);
  52. [self handlePush:userInfo];
  53. }
  54. #pragma mark - dealwith push data
  55. /// 处理来自远程的推送内容
  56. - (void)handlePush:(NSDictionary *)payLoad {
  57. if (payLoad == nil) {
  58. return;
  59. }
  60. NSDictionary *aps = [payLoad valueForKey:@"aps"];
  61. if (aps == nil) {
  62. return;
  63. }
  64. UIApplication *application = [UIApplication sharedApplication];
  65. // 当前 APP 在前台
  66. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
  67. // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
  68. NSLog(@"payLoad=%@",payLoad);
  69. // [self handlePushAction:payLoad]; // 处理推送消息
  70. } else {
  71. [self handlePushAction:payLoad]; // 处理推送消息
  72. }
  73. }
  74. - (void)handlePushAction:(NSDictionary *)payLoad {
  75. NSDictionary *customData = payLoad[@"custom"][@"a"];
  76. NSString *title = customData[@"title"];
  77. NSString *push_para = customData[@"push_para"];
  78. NSString *message_id = customData[@"message_id"];
  79. NSNumber *push_type = customData[@"push_type"];
  80. if (!push_type) {
  81. return;
  82. }
  83. NSInteger type = push_type.integerValue;
  84. // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
  85. }
  86. @end