AppDelegate.m
25.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
//
// AppDelegate.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/17.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "AppDelegate.h"
#import "AvoidCrash.h"
#import "BaiduMobStat.h"//百度统计
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
#import <UserNotifications/UserNotifications.h>
#endif
@interface AppDelegate ()<XGPushDelegate>
{
UIImageView *imageView;
}
@property (nonatomic, assign) BOOL isPush; //区分普通启动还是推送
@property (nonatomic, copy) NSString *type; //区分首页还是直播 还是id
@property (nonatomic, assign) BOOL language; //区分消息是中英文语言
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self restoreStatusBarOrientation];
[[UITabBar appearance] setTranslucent:NO];
#pragma mark - 打包注意
[AvoidCrash makeAllEffective];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//推送
[self registerRemoteNotification];
[self registerNotification:launchOptions];
[[BaiduMobStat defaultStat] startWithAppId:uBaiduMobStat];
//分享
[UMConfigure initWithAppkey:uMengKey channel:nil];
[UMConfigure setLogEnabled:NO];
[[TemplateShareManager manager] shareConfig];
//语言
[self setApplicationLanguage];
//收藏
[[DBAction sharedDBAction] createTable:@"en"];
[[DBAction sharedDBAction] createTable:@"zh"];
//版本更新
[self checkAppUpdate];
[self initializeSDKConfiguration];
[self requestLanchImage];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"lanchImage"];
if (data.length>0) {
UIViewController *VC = [[UIViewController alloc] init];
imageView= [[UIImageView alloc ] initWithFrame :[ UIScreen mainScreen ]. bounds ];
[imageView setImage:[UIImage imageWithData:data]];
[VC.view addSubview:imageView];
self.window.rootViewController = VC;
[self performSelector:@selector(removeImage) withObject:nil afterDelay:3];
[self.window makeKeyAndVisible];
}
return YES;
}
-(void)addRootViewController
{
if(IS_CHINESE){
CNHomeRightViewController *rightVC = [[CNHomeRightViewController alloc]init];
CNLiveTabBarController *liveTab = [[CNLiveTabBarController alloc] init];
XLSlideMenu *slideMenu = [[XLSlideMenu alloc] initWithRootViewController:liveTab];
//设置左右菜单
slideMenu.slideEnabled = NO;
rightVC.block = ^(NSInteger row) {
CNHomeViewController *vc = (CNHomeViewController *)liveTab.viewControllers[0];
vc.segmentControl.current = row;
};
slideMenu.rightViewController = rightVC;
self.window.rootViewController = slideMenu;
}else{
CNLiveENTabBarController *liveTab = [[CNLiveENTabBarController alloc] init];
self.window.rootViewController = liveTab;
}
[self.window makeKeyAndVisible];
}
#pragma mark - 请求启动页
-(void)requestLanchImage
{
NSString *urlStr = REQUESTURL(@"gxb/openBanner");
NSDictionary *parameters = @{@"params":@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"gxb\",\"pageUUID\":\"852cde69-ecd8-11e6-b52e-c7d8a7a18cc4\",\"pageType\":\"channelList\"}"};
[XWHTTPTool GET:urlStr params:parameters success:^(id json) {
NSDictionary *dic = [NSDictionary dictionaryWithDictionary:json];
NSURL *url = [NSURL URLWithString:dic[@"data"][@"image"]];
if ([dic[@"data"][@"grayMode"] isEqualToString:@"true"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:ISGRAYMODE];
}else{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:ISGRAYMODE];
}
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"lanchImage"];
if (data.length<=0) {
[self addRootViewController];
}
NSURLSessionConfiguration *configuration = [ NSURLSessionConfiguration defaultSessionConfiguration ];
AFURLSessionManager *manager = [[ AFURLSessionManager alloc ] initWithSessionConfiguration :configuration];
NSURLRequest *request = [ NSURLRequest requestWithURL :url];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest :request progress : nil destination :^ NSURL *( NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[ NSFileManager defaultManager ] URLForDirectory : NSDocumentDirectory inDomain : NSUserDomainMask appropriateForURL : nil create : NO error : nil ];
return [documentsDirectoryURL URLByAppendingPathComponent :[response suggestedFilename ]];
} completionHandler :^( NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog ( @"File downloaded to: %@" , filePath);
NSData * image = [NSData dataWithContentsOfURL :filePath];
[[ NSUserDefaults standardUserDefaults ] setObject :image forKey : @"lanchImage"];
}];
[downloadTask resume ];
} failure:^(NSError *error) {
[self requestLanchImage];
}];
}
-(void)removeImage{
[imageView removeFromSuperview];
imageView = nil;
[self addRootViewController];
}
//语言
#pragma mark - 语言
- (void)setApplicationLanguage{
//优先考虑本地存储语言
if ([User_Defaults objectForKey:Language_Local]) {
if ([[User_Defaults objectForKey:Language_Local] isEqualToString:@"en"]) {
self.lan = @"en";
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"Done";
}
if ([[User_Defaults objectForKey:Language_Local] isEqualToString:@"zh-Hans"]) {
self.lan = @"zh-Hans";
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"完成";
}
}
else{
//获取系统语言
if (IS_CHINESE) {
self.lan =@"zh-Hans";
[User_Defaults setObject:@"zh-Hans" forKey:Language_Local];
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"完成";
}else{
self.lan =@"en";
[User_Defaults setObject:@"en" forKey:Language_Local];
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"Done";
}
}
}
- (NSString *)showText:(NSString *)key{
NSString *path = [[NSBundle mainBundle] pathForResource:_lan ofType:@"lproj"];
return [[NSBundle bundleWithPath:path] localizedStringForKey:key value:nil table:@"Localizable"];
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
self.isPush = NO;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
if (self.isPush) {
if([self.window.rootViewController isKindOfClass:[XLSlideMenu class]]){
XLSlideMenu *menu = (XLSlideMenu *)self.window.rootViewController;
CNLiveTabBarController *tabVC = (CNLiveTabBarController *)menu.rootViewController;
//直播
if([self.type isEqualToString:@"1"]){
tabVC.selectedIndex = 1;
}else{
//1选中答记者问或者国新视界
tabVC.selectedIndex = 0;
//2请求跳转
[self getDataById:_type];
}
}else if([self.window.rootViewController isKindOfClass:[UITabBarController class]]){
CNLiveENTabBarController *tabVC = (CNLiveENTabBarController *)self.window.rootViewController;
tabVC.selectedIndex = 0;
//直播
if(![self.type isEqualToString:@"1"]){
//2请求跳转
[self getDataById:_type];
}
}
}
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error);
[[NSNotificationCenter defaultCenter] postNotificationName:@"RegisterDeviceFailed" object:nil];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
//当APP在前台运行时,不做处理
if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive){
}
//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面
else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive){
NSLog(@"收到推送:%@",userInfo);
for (NSString *tfStr in userInfo){
if ([tfStr isEqualToString:@"careline"]) {
}
}
}
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
return YES;
}
#pragma mark - 推送
- (void)registerNotification:(NSDictionary *)launchOptions{
[[XGPush defaultManager] setEnableDebug:YES];
XGNotificationAction *action1 = [XGNotificationAction actionWithIdentifier:@"xgaction001" title:@"xgAction1" options:XGNotificationActionOptionNone];
XGNotificationAction *action2 = [XGNotificationAction actionWithIdentifier:@"xgaction002" title:@"xgAction2" options:XGNotificationActionOptionDestructive];
if (action1 && action2) {
XGNotificationCategory *category = [XGNotificationCategory categoryWithIdentifier:@"xgCategory" actions:@[action1, action2] intentIdentifiers:@[] options:XGNotificationCategoryOptionNone];
XGNotificationConfigure *configure = [XGNotificationConfigure configureNotificationWithCategories:[NSSet setWithObject:category] types:XGUserNotificationTypeAlert|XGUserNotificationTypeBadge|XGUserNotificationTypeSound];
if (configure) {
[[XGPush defaultManager] setNotificationConfigure:configure];
}
}
[[XGPush defaultManager] startXGWithAppID:2200300438 appKey:@"IF5M37BQ66BM" delegate:self];
[[XGPush defaultManager] setXgApplicationBadgeNumber:0];
[[XGPush defaultManager] reportXGNotificationInfo:launchOptions];
}
- (void)registerRemoteNotification{
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
#pragma mark - 数据请求
- (void)getDataById:(NSString *)idStr{
if (![[Reachability reachabilityForInternetConnection] currentReachabilityStatus]) {
[AlertViewTool showHUDViewText:CustomStr(@"NetworkiInterruption")];
return;
}
NSString *strUrl = REQUESTURL(@"gxb/api/programByContentId");
NSString *parameter = [NSString stringWithFormat:@"{\"plat\":\"i\",\"version\":\"5.0\",\"appid\":\"38_iuvkou3xi05\",\"cmsContentId\":\"%@\"}",idStr];
NSDictionary *parameters = @{@"params":parameter};
[AlertViewTool showHUDView];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:strUrl parameters:parameters headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {}
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// 请求成功,解析数据
NSError *err;
NSDictionary *dicData = [NSJSONSerialization JSONObjectWithData:responseObject
options:NSJSONReadingMutableContainers
error:&err];
NSDictionary *dic = dicData[@"program"];
if(dic){
if([self.window.rootViewController isKindOfClass:[XLSlideMenu class]]){
XLSlideMenu *menu = (XLSlideMenu *)self.window.rootViewController;
CNLiveTabBarController *tabVC = (CNLiveTabBarController *)menu.rootViewController;
UINavigationController *nav = tabVC.childViewControllers[0];
//判断推送消息是中文还是英文(初始化sdk配置)
[self initializeSDKConfigurationByLanguage:self.language];
//视频
if([@"program" isEqualToString:dic[@"type"]]){
OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:dic];
vc.title = dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
}
//文本
else if([@"article" isEqualToString:dic[@"type"]]){
OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:dic];
vc.title = dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
}
}else if([self.window.rootViewController isKindOfClass:[UITabBarController class]]){
CNLiveENTabBarController *tabVC = (CNLiveENTabBarController *)self.window.rootViewController;
UINavigationController *nav = tabVC.childViewControllers[0];
//判断推送消息是中文还是英文(初始化sdk配置)
[self initializeSDKConfigurationByLanguage:self.language];
//视频
if([@"program" isEqualToString:dic[@"type"]]){
OldVideoDetailViewController *vc = [[OldVideoDetailViewController alloc] initWithDictionary:dic];
vc.title = dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
}
//文本
else if([@"article" isEqualToString:dic[@"type"]]){
OldArticleDetailViewController *vc = [[OldArticleDetailViewController alloc] initWithDictionary:dic];
vc.title = dic[@"cmsColumnName"];
vc.hidesBottomBarWhenPushed = YES;
[nav pushViewController:vc animated:YES];
}
}
}
[AlertViewTool hideHUDView];
}
failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
// 请求失败
NSLog(@"%@", [error localizedDescription]);
[AlertViewTool hideHUDView];
[AlertViewTool showHUDViewText:CustomStr(@"ServerBusy")];
}];
}
- (NSString *)type{
if (!_type) {
_type = [NSString stringWithFormat:@"0"];
}
return _type;
}
/**
收到通知消息的回调,通常此消息意味着有新数据可以读取(iOS 7.0+)
@param application UIApplication 实例
@param userInfo 推送时指定的参数
@param completionHandler 完成回调
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGDemo] receive slient Notification");
NSLog(@"[XGDemo] userinfo %@", userInfo);
//当APP在前台运行时,不做处理
if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive){
}
//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面
else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive){
// self.type = response.notification.request.content.categoryIdentifier;
}
[[XGPush defaultManager] reportXGNotificationInfo:userInfo];
completionHandler(UIBackgroundFetchResultNewData);
}
// iOS 10 新增 API
// iOS 10 会走新 API, iOS 10 以前会走到老 API
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// App 用户点击通知
// App 用户选择通知中的行为
// App 用户在通知中心清除消息
// 无论本地推送还是远程推送都会走这个回调
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler API_AVAILABLE(ios(10.0)){
//当APP在前台运行时,不做处理
if( [UIApplication sharedApplication].applicationState == UIApplicationStateActive){
}
//当APP在后台运行时,当有通知栏消息时,点击它,就会执行下面的方法跳转到相应的页面
else if ([UIApplication sharedApplication].applicationState == UIApplicationStateInactive)
{
NSString *str = response.notification.request.content.categoryIdentifier;
NSArray *arr = [str componentsSeparatedByString:@"&"];
self.type = arr.count == 2? arr[0] : str;
if(arr.count == 2&&[arr[1] isEqualToString:@"en"]){
//英文
self.language = NO;
}else{
//中文
self.language = YES;
}
self.isPush = YES;
}
NSLog(@"[XGDemo] click notification");
if ([response.actionIdentifier isEqualToString:@"xgaction001"]) {
NSLog(@"click from Action1");
} else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) {
NSLog(@"click from Action2");
}
if (@available(iOS 10.0, *)) {
[[XGPush defaultManager] reportXGNotificationResponse:response];
} else {
// Fallback on earlier versions
}
completionHandler();
}
// App 在前台弹通知需要调用这个接口
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler API_AVAILABLE(ios(10.0)){
[[XGPush defaultManager] reportXGNotificationInfo:notification.request.content.userInfo];
if (@available(iOS 10.0, *)) {
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
} else {
// Fallback on earlier versions
}
}
#endif
#pragma mark - XGPushDelegate
- (void)xgPushDidFinishStart:(BOOL)isSuccess error:(NSError *)error {
NSLog(@"%s, result %@, error %@", __FUNCTION__, isSuccess?@"OK":@"NO", error);
// UIViewController *ctr = [self.window rootViewController];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"启动信鸽服务%@",isSuccess ? @"成功":@"失败"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
// [alert show];
}
- (void)xgPushDidFinishStop:(BOOL)isSuccess error:(NSError *)error {
// UIViewController *ctr = [self.window rootViewController];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"启动信鸽服务%@",isSuccess ? @"成功":@"失败"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
// [alert show];
}
- (void)xgPushDidRegisteredDeviceToken:(NSString *)deviceToken error:(NSError *)error {
NSLog(@"token:%@",deviceToken);
NSLog(@"%s, result %@, error %@", __FUNCTION__, error?@"NO":@"OK", error);
}
#pragma mark - SDK Configuration
- (void)initializeSDKConfiguration{
//注册APP
[CNLiveStat registerApp:CNLiveAppId appKey:CNLiveAppKey];
//启动事件
[CNLiveStat event:@"start"];
//初始化直播SDK
[[CNLiveWebcastManager manager] initWithAppId:CNLiveAppId appKey:CNLiveAppKey];
//用户SDK初始化
// [CNLiveUserSystemCenter setAppId:CNLiveAppId appKey:CNLiveAppKey appSecret:CNLiveAppSecret];
[CNLiveUserSystemCenter setAppId:@"38_ivkou3xi05" appKey:@"a38d0547d9699d3c3b2cb4482c7166f313f484cc3262fe" appSecret:@"02243d3cdc1ee0650ee12fcf0cd4f1ec1ee9b8af018618"];
}
- (void)initializeSDKConfigurationByLanguage:(BOOL)isChinese{
if(isChinese){
//注册APP
[CNLiveStat registerApp:@"38_ivkou3xi05" appKey:@"a38d0547d9699d3c3b2cb4482c7166f313f484cc3262fe"];
//启动事件
[CNLiveStat event:@"start"];
//初始化直播SDK
[[CNLiveWebcastManager manager] initWithAppId:@"38_ivkou3xi05" appKey:@"a38d0547d9699d3c3b2cb4482c7166f313f484cc3262fe"];
//用户SDK初始化
// [CNLiveUserSystemCenter setAppId:@"38_ivkou3xi05" appKey:@"a38d0547d9699d3c3b2cb4482c7166f313f484cc3262fe" appSecret:@"02243d3cdc1ee0650ee12fcf0cd4f1ec1ee9b8af018618"];
}else{
//注册APP
[CNLiveStat registerApp:@"858_jloqel8r83" appKey:@"84d2370e021b40bc41889d4011fce1fb8af85598a9fcae"];
//启动事件
[CNLiveStat event:@"start"];
//初始化直播SDK
[[CNLiveWebcastManager manager] initWithAppId:@"858_jloqel8r83" appKey:@"84d2370e021b40bc41889d4011fce1fb8af85598a9fcae"];
//用户SDK初始化
// [CNLiveUserSystemCenter setAppId:@"858_jloqel8r83" appKey:@"84d2370e021b40bc41889d4011fce1fb8af85598a9fcae" appSecret:@"1d68c27291e847b3f4d8828420d8f5f2afbd77b492f1b8"];
}
}
#pragma mark - 版本更新
- (void)checkAppUpdate{
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *nowVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@", uAppId]];
NSString * file = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSDictionary *dic = [file objectFromJSONString];
NSDictionary *results = [[dic objectForKey:@"results"] firstObject];
NSString *newVersion =[results objectForKey:@"version"];
if([newVersion compare:nowVersion options:NSNumericSearch] == NSOrderedDescending) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"upDate"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:CustomStr(@"VersionUpdate")
message:[results objectForKey:@"releaseNotes"]
delegate:self
cancelButtonTitle:CustomStr(@"Cancel")
otherButtonTitles:CustomStr(@"Update"),nil];
[alert show];
return;
}
}
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1){
// 此处加入应用在app store的地址,方便用户去更新,一种实现方式如下:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/us/app/id%@?ls=1&mt=8", uAppId]];
[[UIApplication sharedApplication] openURL:url];
}
}
- (BOOL)shouldAutorotate {
return NO;
}
- (void)restoreStatusBarOrientation {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(setStatusBarOrientation:)]) {
SEL selector = NSSelectorFromString(@"setStatusBarOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIApplication instanceMethodSignatureForSelector:selector]];
UIDeviceOrientation orentation = UIDeviceOrientationPortrait;
[invocation setSelector:selector];
[invocation setTarget:[UIApplication sharedApplication]];
[invocation setArgument:&orentation atIndex:2];
[invocation invoke];
}
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
@end