254 lines
11 KiB
Mathematica
254 lines
11 KiB
Mathematica
|
|
//
|
|||
|
|
// AppDelegate.m
|
|||
|
|
// AppScaffold
|
|||
|
|
//
|
|||
|
|
// Created by 谢培艺 on 2020/3/14.
|
|||
|
|
// Copyright © 2020 ko1o. All rights reserved.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import "AppDelegate.h"
|
|||
|
|
#import "AppSetup.h"
|
|||
|
|
#import "TUILogin.h"
|
|||
|
|
#import <WXApi.h>
|
|||
|
|
#import <Bugly/Bugly.h>
|
|||
|
|
#import "ApplePayService.h"
|
|||
|
|
#import <V2TIMManager+APNS.h>
|
|||
|
|
#import "TUIMessageDataProvider+TUIPatch.h"
|
|||
|
|
//#import <UMShare/UMShare.h>
|
|||
|
|
|
|||
|
|
//#import <BaiduActionSDK/BaiduAction.h>
|
|||
|
|
#import "AppDelegate+THSetup.h"
|
|||
|
|
#import "AppDelegate+THCustomTabBarController.h"
|
|||
|
|
//#import "CYHProvinceCityAreaHelper.h"
|
|||
|
|
//#import "THLivePlayScrollViewController.h"
|
|||
|
|
|
|||
|
|
@interface AppDelegate ()
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
@implementation AppDelegate
|
|||
|
|
|
|||
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|||
|
|
|
|||
|
|
// [self setupCustomTabBarControllerAndAppearance];
|
|||
|
|
// return YES;
|
|||
|
|
|
|||
|
|
[self setupReachabilityStatusNotification];
|
|||
|
|
[PYHTTPManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
|||
|
|
//网络状态更改
|
|||
|
|
BOOL isWanAndWifi = (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi);
|
|||
|
|
if (isWanAndWifi) {
|
|||
|
|
[self setupGT_QuickAuthorizeAndPreGetToken];
|
|||
|
|
[self setupIDFA];
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:LoginSuccessNotification object:nil];
|
|||
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(logoutSuccess) name:LogoutSuccessNotification object:nil];
|
|||
|
|
|
|||
|
|
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
|||
|
|
// self.window.rootViewController = [[THNavigationController alloc] initWithRootViewController:[THLivePlayScrollViewController new]];
|
|||
|
|
// [self.window makeKeyAndVisible];
|
|||
|
|
// return YES;
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 获取app配置
|
|||
|
|
[PYAppService appConfig];
|
|||
|
|
[TUILogin initWithSdkAppID:TIM_APPID]; // SDKAppID 可以在 即时通信 IM 控制台中获取
|
|||
|
|
[Bugly startWithAppId:BUGLY_APPID];
|
|||
|
|
|
|||
|
|
// apple pay 处理
|
|||
|
|
[[ApplePayService sharedInstance] autoHandleUpdatedTransactions];
|
|||
|
|
// 初始化
|
|||
|
|
[AppSetup initSetupWithWindow:self.window];
|
|||
|
|
|
|||
|
|
|
|||
|
|
//初始化会员购买支付回调
|
|||
|
|
[PYAppService sharedService];
|
|||
|
|
|
|||
|
|
///个推_推送SDK初始化
|
|||
|
|
[self setupGT_PushWithlaunchingOptions:launchOptions];
|
|||
|
|
|
|||
|
|
// [BaiduAction init:@"16447" secretKey:@"76ddbf4c626e5ed4612607dfbbb6eaad"];
|
|||
|
|
|
|||
|
|
//让启动页显示一会儿
|
|||
|
|
[NSThread sleepForTimeInterval:1.5];
|
|||
|
|
|
|||
|
|
return YES;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
|
|||
|
|
return UIInterfaceOrientationMaskPortrait; // 强制竖屏
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)loginSuccess {
|
|||
|
|
[AppSetup setupWindowRootVCWithWindow:self.window isLanuch:NO];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)logoutSuccess {
|
|||
|
|
[AppSetup setupWindowRootVCWithWindow:self.window isLanuch:NO];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
|
|||
|
|
{
|
|||
|
|
// if ([[UMSocialManager defaultManager] handleUniversalLink:userActivity options:nil]) {
|
|||
|
|
// // 其他SDK的回调
|
|||
|
|
// return YES;
|
|||
|
|
// }
|
|||
|
|
// 处理微信回调
|
|||
|
|
if ([WXApi handleOpenUniversalLink:userActivity delegate:[PYAppService sharedService]]) {
|
|||
|
|
return YES;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ([PYAppService handleUrl:userActivity.webpageURL.absoluteString]) {
|
|||
|
|
return YES;
|
|||
|
|
}
|
|||
|
|
return NO;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 仅支持iOS9以上系统
|
|||
|
|
- (BOOL)application:(UIApplication*)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id>*)options
|
|||
|
|
{
|
|||
|
|
// 处理微信回调
|
|||
|
|
if ([WXApi handleOpenURL:url delegate:[PYAppService sharedService]]) {
|
|||
|
|
return YES;
|
|||
|
|
} else if ([url.host isEqualToString:@"safepay"]) {
|
|||
|
|
//跳转支付宝钱包进行支付,处理支付结果
|
|||
|
|
// [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
|
|||
|
|
// NSLog(@"result = %@",resultDic);
|
|||
|
|
// [PYAppService checkPayResult];
|
|||
|
|
// }];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 6.3的新的API调用,是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
|
|||
|
|
// if ([[UMSocialManager defaultManager] handleOpenURL:url options:options]) {
|
|||
|
|
// // 其他如支付等SDK的回调
|
|||
|
|
// return YES;
|
|||
|
|
// }
|
|||
|
|
if ([PYAppService handleUrl:url.absoluteString]) {
|
|||
|
|
return YES;
|
|||
|
|
}
|
|||
|
|
return NO;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - Notification
|
|||
|
|
|
|||
|
|
//在 AppDelegate 的回调中会返回 deviceToken,需要在登录后上报给腾讯云后台
|
|||
|
|
-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
|
|||
|
|
{
|
|||
|
|
//记录下 Apple 返回的 deviceToken
|
|||
|
|
self.deviceToken = deviceToken;
|
|||
|
|
|
|||
|
|
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
|
|||
|
|
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|||
|
|
NSLog(@"\n>>>[DeviceToken Success]:%@\n\n", token);
|
|||
|
|
|
|||
|
|
V2TIMAPNSConfig *confg = [[V2TIMAPNSConfig alloc] init];
|
|||
|
|
/* 用户自己到苹果注册开发者证书,在开发者帐号中下载并生成证书(p12 文件),将生成的 p12 文件传到腾讯证书管理控制台,控制台会自动生成一个证书 ID,将证书 ID 传入以下 busiId 参数中。*/
|
|||
|
|
//推送证书 ID
|
|||
|
|
confg.businessID = TIM_PUSHID;
|
|||
|
|
// confg.token = self.deviceToken;
|
|||
|
|
NSLog(@"push token %@", [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding]);
|
|||
|
|
confg.token = deviceToken;
|
|||
|
|
[[V2TIMManager sharedInstance] setAPNS:confg succ:^{
|
|||
|
|
NSLog(@"register push success");
|
|||
|
|
} fail:^(int code, NSString *msg) {
|
|||
|
|
NSLog(@"register push fail %s %d, %@", __func__, code, msg);
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(nonnull NSError *)error
|
|||
|
|
{
|
|||
|
|
NSLog(@"register push fail %@", error);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//启动 APP 后会收到以下回调
|
|||
|
|
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
|
|||
|
|
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
|
|||
|
|
// 解析推送扩展字段 desc
|
|||
|
|
if ([userInfo[@"ext"] isEqualToString:NewC2CMessage]) {
|
|||
|
|
//TODO hely @peiyi 回到rootviewcontrooler,并跳转到消息Tab
|
|||
|
|
[PYAppService setTabbarSelectedItem:0];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - Getui SDK Delegate
|
|||
|
|
|
|||
|
|
/// [ GTSDK回调 ] SDK运行状态通知
|
|||
|
|
- (void)GeTuiSDkDidNotifySdkState:(SdkStatus)aStatus {
|
|||
|
|
NSLog(@"GeTuiSDkDidNotifySdkState %lu", (unsigned long)aStatus);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/** SDK启动成功返回cid */
|
|||
|
|
- (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
|
|||
|
|
//个推SDK已注册,返回clientId
|
|||
|
|
NSLog(@"\n>>>[GeTuiSdk RegisterClient]:%@\n\n", clientId);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - Getui Push
|
|||
|
|
|
|||
|
|
//// 个推 push
|
|||
|
|
/// 通知展示(iOS10及以上版本)
|
|||
|
|
/// @param center center
|
|||
|
|
/// @param notification notification
|
|||
|
|
/// @param completionHandler completionHandler
|
|||
|
|
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification completionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
|
|||
|
|
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), notification.request.content.userInfo];
|
|||
|
|
NSLog(@"%@", msg);
|
|||
|
|
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要,判断是否要提示用户Badge、Sound、Alert等
|
|||
|
|
//completionHandler(UNNotificationPresentationOptionNone); 若不显示通知,则无法点击通知
|
|||
|
|
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// 收到通知信息
|
|||
|
|
/// @param userInfo apns通知内容
|
|||
|
|
/// @param center UNUserNotificationCenter(iOS10及以上版本)
|
|||
|
|
/// @param response UNNotificationResponse(iOS10及以上版本)
|
|||
|
|
/// @param completionHandler 用来在后台状态下进行操作(iOS10以下版本)
|
|||
|
|
- (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo notificationCenter:(UNUserNotificationCenter *)center response:(UNNotificationResponse *)response fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
|||
|
|
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), userInfo];
|
|||
|
|
NSLog(@"%@", msg);
|
|||
|
|
if(completionHandler) {
|
|||
|
|
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
|
|||
|
|
completionHandler(UIBackgroundFetchResultNoData);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// 收到透传消息
|
|||
|
|
/// @param userInfo 推送消息内容
|
|||
|
|
/// @param fromGetui YES: 个推通道 NO:苹果apns通道
|
|||
|
|
/// @param offLine 是否是离线消息,YES.是离线消息
|
|||
|
|
/// @param appId 应用的appId
|
|||
|
|
/// @param taskId 推送消息的任务id
|
|||
|
|
/// @param msgId 推送消息的messageid
|
|||
|
|
/// @param completionHandler 用来在后台状态下进行操作(通过苹果apns通道的消息 才有此参数值)
|
|||
|
|
- (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo fromGetui:(BOOL)fromGetui offLine:(BOOL)offLine appId:(NSString *)appId taskId:(NSString *)taskId msgId:(NSString *)msgId fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
|||
|
|
// [ GTSDK ]:汇报个推自定义事件(反馈透传消息),开发者可以根据项目需要决定是否使用, 非必须
|
|||
|
|
// [GeTuiSdk sendFeedbackMessage:90001 andTaskId:taskId andMsgId:msgId];
|
|||
|
|
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APN] %@ \nReceive Slience: fromGetui:%@ appId:%@ offLine:%@ taskId:%@ msgId:%@ userInfo:%@ ", NSStringFromSelector(_cmd), fromGetui ? @"个推消息" : @"APNs消息", appId, offLine ? @"离线" : @"在线", taskId, msgId, userInfo];
|
|||
|
|
NSLog(@"%@", msg);
|
|||
|
|
|
|||
|
|
if(completionHandler) {
|
|||
|
|
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
|
|||
|
|
completionHandler(UIBackgroundFetchResultNoData);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification {
|
|||
|
|
// [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
- (void)GeTuiSdkDidOccurError:(NSError *)error {
|
|||
|
|
NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [GeTuiSdk GeTuiSdkDidOccurError]:%@\n\n",error.localizedDescription];
|
|||
|
|
|
|||
|
|
// SDK发生错误时,回调异常错误信息
|
|||
|
|
NSLog(@"%@", msg);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
@end
|