// // AppDelegate.m // AICity // // Created by wei.z on 2019/7/16. // Copyright © 2019 wei.z. All rights reserved. // #import "AppDelegate.h" #import "CTTabbarController.h" #import #import #import "LoginViewController.h" #import "SearchResultViewController.h" #import "PlayHistoryViewController.h" #import "FavViewController.h" #import "ZFNormalViewController.h" #import "DelAccountViewController.h" #import "LoginWithPassViewController.h" // 腾讯云播放器SDK - 短剧秒切功能需要 // 参考: specs/004-/quickstart.md #import #import #import "JXCrashHandler.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 0. 安装崩溃处理器(最优先执行) [[JXCrashHandler sharedHandler] installCrashHandler]; NSLog(@"[AppDelegate] JXCrashHandler installed"); // 1. 配置腾讯云播放器License和全局缓存(T004 - 短剧秒切功能) // 参考: specs/004-/quickstart.md 第121-154行 [self initTencentPlayerSDK]; // 2. 初始化Window和Root ViewController self.window = [[UIWindow alloc] initWithFrame:kScreenBounds]; [self.window makeKeyAndVisible]; if(![UserModel userToken]){ LoginWithPassViewController *vtab=[[LoginWithPassViewController alloc] init]; self.window.rootViewController=vtab; }else{ CTTabbarController *vtab=[[CTTabbarController alloc] init]; self.window.rootViewController=vtab; } // LoginViewController *vtab = [LoginViewController new]; // SearchResultViewController *vtab = [SearchResultViewController new]; // PlayHistoryViewController *vtab = [PlayHistoryViewController new]; // FavViewController *vtab = [FavViewController new]; // ZFNormalViewController *vtab = [ZFNormalViewController new]; // DelAccountViewController *vtab = [DelAccountViewController new]; [self setNavBar]; return YES; } /** * 初始化腾讯云播放器SDK * * 功能: * 1. 配置License授权 * 2. 配置全局缓存(500MB,支持短剧秒切功能) * 3. 配置备用域名 * * 参考: * - https://cloud.tencent.com/document/product/881/118602 (TXPlayerGlobalSetting) * - specs/004-/quickstart.md * - specs/004-/research.md */ - (void)initTencentPlayerSDK { // 0. 配置日志级别 - 显示所有级别日志 [TXLiveBase setLogLevel:LOGLEVEL_NULL]; // 设置环境变量启用TPPlayer详细日志 setenv("TPPLAYER_LOG_LEVEL", "0", 1); setenv("TPPLAYER_ENABLE_CONSOLE_LOG", "0", 1); setenv("TXLITEAV_LOG_LEVEL", "0", 1); // 1. 配置License // TODO: 替换为实际的License URL和Key // 获取方式: https://console.cloud.tencent.com/vod/license NSString *licenceURL = @"https://license.vod2.myqcloud.com/license/v2/1314161253_1/v_cube.license"; NSString *licenceKey = @"99c843cd9e1a46a589fbd1a76cd244f6"; [TXLiveBase setLicenceURL:licenceURL key:licenceKey]; NSLog(@"Tencent Player License configured"); // 2. 配置全局缓存目录(SDK会自动管理LRU清理) NSString *cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]; cachePath = [cachePath stringByAppendingPathComponent:@"video_cache"]; [TXPlayerGlobalSetting setCacheFolderPath:cachePath]; NSLog(@"Tencent Player cache folder: %@", cachePath); // 3. 设置最大缓存大小(500MB,符合FR-014) [TXPlayerGlobalSetting setMaxCacheSize:500]; NSLog(@"Tencent Player max cache size: 500MB"); // 4. 设置备用域名(提高播放成功率) NSArray *backupHosts = @[@"playvideo.qcloud.com", @"vod.qcloud.com"]; [TXPlayerGlobalSetting setPlayCGIHosts:backupHosts]; NSLog(@"Tencent Player backup hosts configured"); } //设置通用navBar -(void)setNavBar{ [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];//UIColorWithRGB(0x076fea)]; [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIColorWithRGB(0x333333),NSForegroundColorAttributeName,[UIFont systemFontOfSize:18],NSFontAttributeName,nil]]; [[UINavigationBar appearance] setShadowImage:[self imageWithColor:UIColorWithRGBA(243, 243, 243, 243)]]; [UINavigationBar appearance].translucent=NO; } - (UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } /// 在这里写支持的旋转方向,为了防止横屏方向,应用启动时候界面变为横屏模式 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { ZFInterfaceOrientationMask orientationMask = [ZFLandscapeRotationManager supportedInterfaceOrientationsForWindow:window]; if (orientationMask != ZFInterfaceOrientationMaskUnknow) { return (UIInterfaceOrientationMask)orientationMask; } /// 这里是非播放器VC支持的方向 return UIInterfaceOrientationMaskPortrait; } - (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. } - (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. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end