123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // AppDelegate.m
- // Temperature
- //
- // Created by RD on 2022/10/21.
- //
- #import "AppDelegate.h"
- #import "RDSRootControl.h"
- #import <MMKV/MMKV.h>
- #import <WebKit/WebKit.h>
- #import <GTSDK/GeTuiSdk.h>
- #import "Utils.h"
- @interface AppDelegate ()<GeTuiSdkDelegate>
- @property (nonatomic, strong) WKWebView *webView;
- @end
- @implementation AppDelegate
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
-
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- [RDSRootControl shareControl].isFirst = YES;
- self.window.rootViewController = [RDSRootControl shareControl].rootViewController;
- [self.window makeKeyAndVisible];
- self.window.backgroundColor = RDSViewBgColor;
-
- // 初始化MMKV
- // [MMKV initializeMMKV:nil];
-
- // 设置全局userAgent
- self.webView = [[WKWebView alloc] init];
- [_webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable result, NSError * _Nullable error) {
- NSString *newUserAgent = [result stringByAppendingFormat:@"/%@", @"yongxulvjian"];
- [[NSUserDefaults standardUserDefaults] registerDefaults:@{@"UserAgent":newUserAgent}];
- }];
-
- // 自动登录
- if(!kNULLString(TheDataManager.token)){
- [RDSDemoApiHelper rds_refreshTokenSuccess:^(id responseObject) {
- if ([responseObject[@"code"] intValue] == 0) {
- [RDSRootControl shareControl].isLoginSuccess = YES;
- NSDictionary *data = responseObject[@"data"];
- TheDataManager.token = [NSString stringWithFormat:@"%@ %@",data[@"token_type"], data[@"access_token"]];
- } else{
- }
- } failure:^(NSError *error) {
- }];
- }
- self.window.userInteractionEnabled = YES;
-
- // [RDSHudShower setupHUD];
- // 启动图片延时1秒
- // [NSThread sleepForTimeInterval:1];
- NSDictionary *dic = [[NSDictionary alloc]init];
- [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self launchingOptions:dic];
-
- UNAuthorizationOptions types = (UNAuthorizationOptionBadge |
- UNAuthorizationOptionAlert |
- UNAuthorizationOptionSound);
- [GeTuiSdk registerRemoteNotification:types];
- //清空通知和角标
- [GeTuiSdk clearAllNotificationForNotificationBar];
- [self p_appInit];
- // NSString *language = [[NSUserDefaults standardUserDefaults] valueForKey:@"AppleLanguages"];
- // DDLog(@"系统语言:%@",language);
- // [[NSUserDefaults standardUserDefaults] setObject:@[@"zh-Hans"] forKey:@"AppleLanguages"];
- // [[NSUserDefaults standardUserDefaults] synchronize];
-
- return YES;
- }
- -(void)p_appInit
- {
- [RDSDemoApiHelper rds_appInitWithType:@1 success:^(id responseObject) {
-
- } failure:^(NSError *error) {
-
- }];
- }
- /// [ GTSDK回调 ] SDK启动成功返回cid
- - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
- NSLog(@"----clientId----%@", clientId);
- [[NSUserDefaults standardUserDefaults] setObject:clientId forKey:@"cid"];
- }
- - (void)GeTuiSdkNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification completionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
- // NSString *msg = [NSString stringWithFormat:@"[ TestDemo ] [APNs] %@ \n%@", NSStringFromSelector(_cmd), notification.request.content.userInfo];
- // [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要,判断是否要提示用户Badge、Sound、Alert等
- //completionHandler(UNNotificationPresentationOptionNone); 若不显示通知,则无法点击通知
- completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner);
- }
- - (void)GeTuiSdkDidReceiveNotification:(NSDictionary *)userInfo notificationCenter:(UNUserNotificationCenter *)center response:(UNNotificationResponse *)response fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
-
- if(completionHandler) {
- // [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
- completionHandler(UIBackgroundFetchResultNoData);
- }
- }
- - (void)GeTuiSdkDidReceiveSlience:(NSDictionary *)userInfo fromGetui:(BOOL)fromGetui offLine:(BOOL)offLine appId:(NSString *)appId taskId:(NSString *)taskId msgId:(NSString *)msgId fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
-
- //本地通知UserInfo参数
- NSDictionary *dic = nil;
- if (fromGetui) {
- //个推在线透传
- //个推进行本地通知统计 userInfo中必须要有_gmid_参数
- dic = @{@"_gmid_": [NSString stringWithFormat:@"%@:%@", taskId ?: @"", msgId ?: @""]};
- } else {
- //APNs静默通知
- dic = userInfo;
- }
-
- if (fromGetui && offLine == NO) {
- //个推通道+在线,发起本地通知
- [Utils pushLocalNotification:userInfo[@"payload"] userInfo:dic];
- }
-
- if(completionHandler) {
- // [ 参考代码,开发者注意根据实际需求自行修改 ] 根据APP需要自行修改参数值
- completionHandler(UIBackgroundFetchResultNoData);
- }
- }
- - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo fetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler
- {
- //注意,如果执行了上述代理方法中的completionHandler,就不要执行当前回调中的completionHandler。
- //防止两次调用completionHandler引起崩溃
- //completionHandler(UIBackgroundFetchResultNewData);
- }
- -(void)applicationDidEnterBackground:(UIApplication *)application
- {
- [kNotificationCenter postNotificationName:@"kApplicationDidEnterBackground" object:nil];
- }
- -(void)applicationWillEnterForeground:(UIApplication *)application
- {
- [kNotificationCenter postNotificationName:@"kApplicationWillEnterForeground" object:nil];
- }
- @end
|