123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //
- // AppDelegate.m
- // Asteria
- //
- // Created by iOS on 2023/4/22.
- //
- #import "AppDelegate.h"
- #import "AS_TabBarViewController.h"
- #import <YTKNetwork/YTKNetwork.h>
- #import <FBSDKLoginKit/FBSDKLoginKit.h>
- #import <StripeCore/StripeCore-Swift.h>
- #import <OneSignal/OneSignal.h>
- @import Stripe;
- @interface AppDelegate ()<UNUserNotificationCenterDelegate>
- //@property (nonatomic, strong, readonly) UIWindow *window;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- if (@available(iOS 15.0, *)) {
- UITableView.appearance.sectionHeaderTopPadding = 0;
- } else {
- // Fallback on earlier versions
- }
-
-
- [ASCurrencyManager.shared getAllCurrencyData];
- [ASNetTools reqNet_getAdvCoupons];
-
- // [self xxx_ytkNetConfig];
- [PPNetworkHelper openLog];
-
- self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
- AS_TabBarViewController *tab = [[AS_TabBarViewController alloc] init];
- tab.selectedIndex = 0;
- self.window.rootViewController = tab;
- if (ASUserInfoManager.shared.isLogin ) {
- [ASUserInfoManager.shared getInfo];
- }
- [self.window makeKeyAndVisible];
-
- //StripeAPI
- [StripeAPI setDefaultPublishableKey:StripePublishableKey];
-
- // 为了使用 Facebook SDK 应该调用如下方法
- [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
- // 注册 FacebookAppID
- [[FBSDKSettings sharedSettings] setAppID:Facebook_AppID];
-
- //推送相关配置
- [self oneSignalPushConfig:launchOptions];
-
- [UNUserNotificationCenter currentNotificationCenter].delegate = self;
- [self pushAuthRequest];
- // [OneSignal sendTag:@"SufixUid" value:@"-"];
- // [self updateUserData];
-
- return YES;
- }
- -(void)xxx_ytkNetConfig{
- YTKNetworkAgent *agent = [YTKNetworkAgent sharedAgent];
- [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"];
- YTKNetworkConfig *config = [YTKNetworkConfig sharedConfig];
- config.securityPolicy.allowInvalidCertificates = YES;
- config.securityPolicy.validatesDomainName = NO;
- config.baseUrl = [NSString stringWithFormat:@"%@",AS_Server];
- NSLog(@"baseUrl-----%@",config.baseUrl)
- }
- - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
- NSLog(@"--------userInfo:%@",userInfo);
- // completionHandler(UIBackgroundFetchResultNewData);
- [self handlePush:userInfo];
-
- }
- #pragma mark - dealwith push data
- /// 处理来自远程的推送内容
- - (void)handlePush:(NSDictionary *)payLoad {
- if (payLoad == nil) {
- return;
- }
-
- NSDictionary *aps = [payLoad valueForKey:@"aps"];
- if (aps == nil) {
- return;
- }
-
- UIApplication *application = [UIApplication sharedApplication];
-
- // 当前 APP 在前台
- if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) { //活动状态下使用消息提示再提示一下,让用户可以点击
- // 备注:这边比较特殊,当 APP 在前台时,当推送来的时候,会来到这个方法,当点击推送弹窗后,这个方法会再次调用,即这个方法会调用两次,走两次 push 操作.
- NSLog(@"payLoad=%@",payLoad);
- // [self handlePushAction:payLoad]; // 处理推送消息
- } else {
- [self handlePushAction:payLoad]; // 处理推送消息
- }
- }
- - (void)handlePushAction:(NSDictionary *)payLoad {
-
- NSDictionary *customData = payLoad[@"custom"][@"a"];
- NSString *title = customData[@"title"];
- NSString *push_para = customData[@"push_para"];
- NSString *message_id = customData[@"message_id"];
- NSNumber *push_type = customData[@"push_type"];
- if (!push_type) {
- return;
- }
- NSInteger type = push_type.integerValue;
-
-
- // [[KWPushMessageHandler shareInstance] handleMessage:title messageId:message_id pushPara:push_para pushType:type];
-
-
- }
- #pragma mark - **************** applicationDelegate ****************
- - (BOOL)application:(UIApplication *)app
- openURL:(NSURL *)url
- options:(NSDictionary *)options {
-
- [[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options];
-
-
- // nzk Google Signin
- BOOL stripeHandled = [StripeAPI handleStripeURLCallbackWithURL:url];
- if(stripeHandled){
- return YES;
- }
- // nzk Google Signin end
-
- return YES;
- }
- - (void)pushAuthRequest {
- // 申请权限1
- [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
- if (settings.authorizationStatus == UNAuthorizationStatusNotDetermined) {
- UNAuthorizationOptions authOptions =
- UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
- [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:authOptions
- completionHandler:^(BOOL granted, NSError *_Nullable error){
- dispatch_async(dispatch_get_main_queue(), ^{
- [[UIApplication sharedApplication] registerForRemoteNotifications]; //注册获得device Token
- });
- }];
-
- }
- }];
- dispatch_async(dispatch_get_main_queue(), ^{
- [[UIApplication sharedApplication] registerForRemoteNotifications]; //注册获得device Token
- });
- }
- -(void)oneSignalPushConfig:(NSDictionary *)launchOptions{
- /*
- //#ifdef DEBUG
- // [MobPush setAPNsForProduction:NO];
- //#else
- // [MobPush setAPNsForProduction:YES];
- //#endif
- // //设置地区:regionId 默认0(国内),1:海外
- // [MobPush setRegionID:1];
- // //MobPush推送设置(获得角标、声音、弹框提醒权限)
- // MPushNotificationConfiguration *configuration = [[MPushNotificationConfiguration alloc] init];
- // configuration.types = MPushAuthorizationOptionsBadge | MPushAuthorizationOptionsSound | MPushAuthorizationOptionsAlert;
- // [MobPush setupNotification:configuration];
- // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMessage:) name:MobPushDidReceiveMessageNotification object:nil];
- */
-
-
-
- // Remove this method to stop OneSignal Debugging
- [OneSignal setLogLevel:ONE_S_LL_VERBOSE visualLevel:ONE_S_LL_NONE];
-
- // OneSignal initialization
- [OneSignal initWithLaunchOptions:launchOptions];
- [OneSignal setAppId:@"618fe580-bc97-4bf4-b2bb-5039f9dbbc82"];
- // promptForPushNotifications will show the native iOS notification permission prompt.
- // We recommend removing the following code and instead using an In-App Message to prompt for notification permission (See step 8)
- [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
- NSLog(@"User accepted notifications: %d", accepted);
- }];
-
-
-
- // Set your customer userId
- // [OneSignal setExternalUserId:@"userId"];
-
- // Pass in email provided by customer
- // [OneSignal setEmail:@"example@domain.com"];
- // Pass in phone number provided by customer
- // [OneSignal setSMSNumber:@"+11234567890"];
-
-
- // [OneSignal sendTag:@"key" value:@"value"];
-
-
-
-
-
- #ifdef DEBUG
- [PPNetworkHelper openLog];
- #else
- [PPNetworkHelper closeLog];
- #endif
- }
- - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
- // 用户点击了通知
- // 通过response参数处理用户的点击事件
- completionHandler();
- NSDictionary *payLoad = response.notification.request.content.userInfo;
- [self handlePushAction:payLoad];
- }
- @end
|