//
|
// AppDelegate.m
|
// BuWanVideo2.0
|
//
|
// Created by weikou on 16/7/28.
|
// Copyright © 2016年 com.yeshi.buwansheque.ios. All rights reserved.
|
//
|
|
#import "AppDelegate.h"
|
#import "SlideMenuController.h"
|
#import "MainViewController.h"
|
#import "LeftViewController.h"
|
|
#import "GDTSplashAd.h"
|
#import "GDTSDKConfig.h"
|
//#import "GDTTrack.h"
|
#import "AFNetworkReachabilityManager.h"
|
|
//#import "XGPush.h"
|
//#import "XGSetting.h"
|
|
//#import <AlibcTradeSDK/AlibcTradeSDK.h>
|
|
#import "RecommendMainController.h"
|
#import "RecommendController.h"
|
#import "recommendViewController.h"
|
#import "subregionViewController.h"
|
#import "MineViewController.h"
|
#import "discoverViewController.h"
|
#import "LeftViewController.h"
|
#import "SJTabbarViewController.h"
|
#import "UITabBar+mainTab.h"
|
#import "GuessLikeViewController.h"
|
#import "DYDrawVideoController.h"
|
#import "DYNewsController.h"
|
#import "DYNovelController.h"
|
#import "CustomIOSAlertView.h"
|
|
#import <UMCommon/UMCommon.h>
|
//#import <UMShare/UMShare.h>
|
|
#import <BUAdSDK/BUAdSDK.h>
|
#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
#import <AdSupport/ASIdentifierManager.h>
|
|
#import <IQKeyboardManager/IQKeyboardManager.h>
|
|
//内容联盟
|
#import <LCDSDK/LCDSDK.h>
|
|
|
#define LECUsedBundleID @"com.yeshi.buwanshequ.ios"
|
|
#define TICK NSDate *startTime = [NSDate date]
|
#define TOCK NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
|
|
@interface AppDelegate ()<GDTSplashAdDelegate, BUSplashAdDelegate>
|
|
@property (strong,nonatomic) GDTSplashAd *splash;
|
|
@property (nonatomic, strong) BUSplashAd *splashAd;
|
|
@property (nonatomic, strong) RecommendMainController *vcRecommend;
|
|
@property (nonatomic, strong) SJTabbarViewController *tabBarController;
|
|
@property (strong, nonatomic) UIView *bottomView;
|
@property (nonatomic, strong) UIView *viewBot;
|
@property bool isFirstIn;
|
@end
|
|
@implementation AppDelegate
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
TICK;
|
//清空角标
|
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
|
//设置状态栏的字体颜色
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
|
_inited=false;
|
|
TOCK;
|
return YES;
|
}
|
|
- (void) initSDK:(BUCompletionHandler)completionHandler{
|
[self requestIDFA];
|
//集成友盟
|
[self setUmeng];
|
//[MobClick setLogEnabled:YES];
|
|
//集成穿山甲内容联盟
|
[self initCSJAd:completionHandler];
|
|
//广点通注册
|
[GDTSDKConfig registerAppId:GDTADkey];
|
|
|
|
[[IQKeyboardManager sharedManager] setEnable:YES];
|
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
|
[IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
|
[IQKeyboardManager sharedManager].toolbarDoneBarButtonItemText = @"完成";
|
|
|
//设置提示框的样式
|
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
|
[SVProgressHUD setMinimumDismissTimeInterval:3.0];
|
|
if(iOS8){
|
[self registerPushForIOS8];
|
}else{
|
[self registerPush];
|
}
|
|
|
}
|
|
- (void)initData{
|
|
if (_inited){
|
return;
|
}
|
_inited=true;
|
|
// [self requestIDFA];
|
//添加网络监测
|
[self NetworkMonitoring];
|
|
[self fetchCommenConfig];
|
|
[self loadMainView];
|
}
|
|
-(void) showPrivacyAndProtocol{
|
_isFirstIn = YES;
|
self.viewBot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
|
self.viewBot .backgroundColor = [UIColor whiteColor];
|
[self.window.rootViewController.view addSubview:self.viewBot];
|
|
UIView *viewTop = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100)];
|
[self.viewBot addSubview:viewTop];
|
|
|
UIView *views = [[UIView alloc] init];
|
views.backgroundColor = [UIColor whiteColor];
|
[self.viewBot addSubview:views];
|
views.sd_layout.leftEqualToView(self.viewBot).topSpaceToView(viewTop, 0).rightEqualToView(self.viewBot).bottomEqualToView(self.viewBot);
|
|
UIImageView *logos = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"375"]];
|
[views addSubview:logos];
|
logos.sd_layout.centerXEqualToView(views).centerYEqualToView(views).widthIs(KScreenW).heightIs(57);
|
float width = [UIScreen mainScreen].bounds.size.width;
|
float height = [UIScreen mainScreen].bounds.size.height;
|
UIImageView *imageview = [[UIImageView alloc] init];
|
|
CGFloat viewHeight = 0.0;
|
if (width == 320.0f && height<=480.0f) {
|
// iphone4 iphone4s 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x480"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
}else if (width ==320.0f && height==568.0f) {
|
// iphone5 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x568"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
} else if (width ==375.0f) {
|
// iphone6 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"375x667"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"375"]];
|
viewHeight = 63;
|
|
}else{
|
// iphone6 plus 上的default图片
|
_splash.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414x736"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414"]];
|
viewHeight = 69;
|
}
|
if (KIsiPhoneX) {
|
// _splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"1125x2436"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414"]];
|
}
|
imageview.image = [UIImage imageNamed:@"375"];
|
|
UIWindow *keyWindow = self.window;
|
CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
|
|
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, screenH - 100, KScreenW, 100)];
|
_bottomView.backgroundColor = [UIColor whiteColor];
|
|
imageview.frame = CGRectMake(0, 21.5, _bottomView.frame.size.width, 57);
|
[_bottomView addSubview:imageview];
|
|
[keyWindow addSubview:self.bottomView];
|
|
|
|
|
NSString *content=@"尊敬的影视大全用户:\n 由衷的感谢您选择下载我们的影视大全软件。您的个人信息隐私我们非常尊重并得到保护,我们特别在此申明,并对我们的隐私政策主要的一些信息在此罗列,您需要仔细阅读并理解,只有获得您的“同意”后我们才会合理的获得一些必要的信息。如您有任何疑惑,可通过电子邮箱:ysdq-jubao@qq.com向我方询问,我们团队收到信息后将及时为您解答。\n我们的隐私政策必要信息概要如下:\n";
|
content = [content stringByAppendingString:@"一、导言\n"];
|
content = [content stringByAppendingString:@"二、关于我们\n"];
|
content =[content stringByAppendingString:@"三、本《影视大全隐私政策》适用范围、相关词语涵\n"];
|
content =[content stringByAppendingString:@"四、我们如何收集和使用您的个人信息\n"];
|
content =[content stringByAppendingString:@"五、我们如何使用Cookie和同类技术\n"];
|
content = [content stringByAppendingString:@"六、我们如何共享、转让、公开披露您的个人信息五、您对个人信息享有的控制权六、我们如何存储和保护您的个人信息\n"];
|
content = [content stringByAppendingString:@"七、未成年人保护\n"];
|
content =[content stringByAppendingString:@"八、本《影视大全隐私政策》的更新\n"];
|
content =[content stringByAppendingString:@"九、如何联系我们\n"];
|
content =[content stringByAppendingString:@"十、其他\n"];
|
content =[content stringByAppendingString:@"如您想了解更多,您可以阅读影视大全"];
|
|
|
NSMutableAttributedString *rootAttrString=[[NSMutableAttributedString alloc] initWithString:@""];
|
NSMutableParagraphStyle *pstyle=[[NSMutableParagraphStyle alloc] init];
|
//行间距
|
pstyle.lineSpacing=5;
|
|
NSDictionary *attrDict=@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSParagraphStyleAttributeName:pstyle};
|
[rootAttrString insertAttributedString:[[NSAttributedString alloc] initWithString:content attributes:attrDict] atIndex:rootAttrString.length];
|
|
|
|
//隐私政策
|
attrDict=@{NSLinkAttributeName:[NSURL URLWithString:@"http://h5.ysdq.yeshitv.com/privacy_ios.html"],NSFontAttributeName:[UIFont systemFontOfSize:15]};
|
NSAttributedString *attrString=[[NSAttributedString alloc] initWithString:@"《隐私政策》" attributes:attrDict];
|
[rootAttrString insertAttributedString:attrString atIndex:rootAttrString.length];
|
|
[rootAttrString insertAttributedString:[[NSAttributedString alloc] initWithString:@"。"] atIndex:rootAttrString.length];
|
|
// 弹框
|
CustomIOSAlertView *alertView=[[CustomIOSAlertView alloc] init];
|
height = [UIScreen mainScreen].bounds.size.height*2/5;
|
width = [UIScreen mainScreen].bounds.size.width*4/5;
|
UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(0, 50,width ,height)];
|
textView.editable=NO;
|
textView.font = [UIFont systemFontOfSize:20.0];
|
textView.scrollEnabled = YES;
|
|
textView.attributedText =rootAttrString;
|
|
[alertView setContainerView:textView];
|
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"不同意",@"同意并继续", nil]];
|
[alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
|
if(buttonIndex ==0){
|
//拒绝
|
if (@available(iOS 10.0, *)) {
|
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"影视大全需要您同意后才能提供完整的服务" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
|
[alertView show];
|
}
|
|
}else{
|
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"privacy_and_protocol"];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
//同意
|
[alertView close];
|
[self next];
|
}
|
}];
|
//
|
[alertView show];
|
}
|
|
- (void) next{
|
[self initSDK:^(BOOL success, NSError *error) {
|
|
//加载主页内容
|
self.vcRecommend = [[RecommendMainController alloc]init];
|
self.vcRecommend.tabBarItem.image = [[UIImage imageNamed:@"nav_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
self.vcRecommend.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_home_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
UINavigationController *nrecommendVC = [[UINavigationController alloc]initWithRootViewController:self.vcRecommend];
|
|
|
subregionViewController *subVC = [[subregionViewController alloc]init];
|
subVC.tabBarItem.image = [[UIImage imageNamed:@"Camera-拷贝"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
subVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"Camera"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
UINavigationController *nsubVC = [[UINavigationController alloc]initWithRootViewController:subVC];
|
|
|
|
LeftViewController *mineVC = [[LeftViewController alloc]init];
|
mineVC.tabBarItem.image = [[UIImage imageNamed:@"nav_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_mine_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
UINavigationController *nmineVC = [[UINavigationController alloc]initWithRootViewController:mineVC];
|
|
|
//信息流
|
DYDrawVideoController *drawVC = [[DYDrawVideoController alloc]init];
|
drawVC.tabBarItem.image = [[UIImage imageNamed:@"nav_draw_video"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
drawVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_draw_video_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
|
UINavigationController *ndrawVC = [[UINavigationController alloc]initWithRootViewController:drawVC];
|
|
self.tabBarController = [[SJTabbarViewController alloc]init];
|
self.tabBarController.viewControllers = @[nrecommendVC,ndrawVC,nmineVC];//nnovelVC
|
self.tabBarController.tabBar.tintColor = YTHColor(0, 82, 246);
|
self.tabBarController.tabBar.unselectedItemTintColor=YTHColor(153, 153, 153);
|
[self.tabBarController.tabBar setClipsToBounds:YES];
|
self.tabBarController.tabBar.opaque = YES;
|
|
|
NSMutableDictionary *attr3=[NSMutableDictionary dictionary];
|
attr3[NSFontAttributeName]=[UIFont systemFontOfSize:10];
|
[[UITabBarItem appearance]setTitleTextAttributes:attr3 forState:UIControlStateNormal];
|
|
self.window.rootViewController = self.tabBarController;
|
//判断用户是否已经获得Uid
|
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"uid"]!=nil) {
|
//为Uid进行一个赋值,非常重要
|
[YTHsharedManger startManger].Uid = [[NSUserDefaults standardUserDefaults] objectForKey:@"uid"];
|
//加载主视图
|
[self initFinish];
|
} else {
|
//获取Uid
|
[self getUid];
|
}
|
}];
|
}
|
|
- (void) initFinish{
|
[self setupBUAdSDK];
|
}
|
|
- (void)requestIDFA {
|
if (@available(iOS 14, *)) {
|
[ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
|
|
}];
|
|
} else {
|
// Fallback on earlier versions
|
}
|
}
|
|
|
|
- (void)fetchCommenConfig {
|
NSMutableDictionary *parms = [[NSMutableDictionary alloc] init];
|
[parms setObject:@"getConfig" forKey:@"Method"];
|
[[YTHNetInterface startInterface] fetchCommenConfig:parms WithBlock:^(BOOL isSuccessful, id result, NSString *error) {
|
if ([result[@"IsPost"] boolValue]) {
|
[YTHsharedManger startManger].ad = result[@"Data"][@"adNew"];
|
[[NSUserDefaults standardUserDefaults] setObject:result[@"Data"][@"vipLink"]?:@"" forKey:VIPLINK];
|
[[NSUserDefaults standardUserDefaults] setObject:result[@"Data"][@"unRegisterLink"]?:@"" forKey:UNREGISTER_LINK];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
}else{
|
|
}
|
}];
|
}
|
|
|
- (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 throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
if(iOS9){
|
//进入后台
|
if (self.YBackAppDelegate!=nil) {
|
if ([self.YBackAppDelegate respondsToSelector:@selector(OutApplication)]) {
|
[self.YBackAppDelegate OutApplication];
|
}
|
}
|
}
|
//状态栏重现
|
[[UIApplication sharedApplication] setStatusBarHidden:NO];
|
[LCDManager stopOpenGLESActivity];
|
|
}
|
|
- (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 inactive 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.
|
[self initData];
|
if(iOS9){
|
//进入前台
|
if (self.YBackAppDelegate!=nil) {
|
if([self.YBackAppDelegate respondsToSelector:@selector(backApplication)]){
|
[self.YBackAppDelegate backApplication];
|
}
|
}
|
}
|
[LCDManager startOpenGLESActivity];
|
|
//状态栏重现
|
[[UIApplication sharedApplication] setStatusBarHidden:NO];
|
// [GDTTrack activateApp];
|
}
|
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
}
|
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
|
// if (![[UMSocialManager defaultManager] handleOpenURL:url]) {
|
// BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
|
// return result;
|
// }
|
|
return YES;
|
|
}
|
|
//IOS9.0 系统新的处理openURL 的API
|
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
|
// 新接口写法
|
// if (![[UMSocialManager defaultManager] handleOpenURL:url]) {
|
// BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
|
// return result;
|
// }
|
return YES;
|
}
|
|
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
|
|
}
|
|
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
|
{
|
|
}
|
|
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notifications{
|
|
}
|
|
#pragma mark 获取Uid
|
- (void)getUid{
|
[[YTHNetInterface startInterface] getUserWithDevice:[NSString DeviceIdentifier] withSystem:@"1" withblock:^(BOOL isSuccessful, id result, NSString *error) {
|
if (isSuccessful) {
|
NSDictionary *data = (NSDictionary *)result;
|
[YTHsharedManger startManger].Uid =[[data objectForKey:@"Data"] objectForKey:@"Uid"];
|
//CommentUrl
|
NSLog(@"****************\n %@ \n*************8****",data[@"Data"]);
|
NSDictionary *datasourceDic = data[@"Data"];
|
NSUserDefaults *uid = [NSUserDefaults standardUserDefaults];
|
[uid setValue:datasourceDic[@"Uid"] forKey:@"uid"];
|
[uid setValue:datasourceDic[@"ShareUrl"] forKey:@"ShareUrl"];
|
[uid setValue:datasourceDic[@"ShareContent"] forKey:@"ShareContent"];
|
[uid setValue:datasourceDic[@"CommentUrl"] forKey:@"CommentUrl"];
|
[uid setValue:datasourceDic[@"NoticeContent"] forKey:@"NoticeContent"];
|
[uid setValue:datasourceDic[@"TuiGuang"] forKey:@"TuiGuang"];
|
[uid setValue:datasourceDic[@"IOSDownLoad"] forKey:@"IOSDownLoad"];//0为隐藏 非0为显示
|
[uid setValue:datasourceDic[@"ZiXun"] forKey:@"ZiXun"];
|
[uid setValue:datasourceDic[@"ShowAd"] forKey:@"ShowAd"];//是否在福利社的地方弹好评的框,1为弹,0为不弹
|
[uid synchronize];
|
//加载主视图
|
[self initFinish];
|
}else{
|
//判断当前用户是否还保存有Uid,如果没有,要提醒用户暂时不能使用
|
if ([YTHsharedManger startManger].Uid == nil) {
|
//提醒用户暂不能使用,请检查网络
|
//还是允许用户进入
|
[self initFinish];
|
}
|
}
|
}];
|
}
|
|
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window {
|
// if ([NSStringFromClass([[[window subviews]lastObject] class]) isEqualToString:@"UITransitionView"]) {
|
// return UIInterfaceOrientationMaskAll;
|
// }
|
return UIInterfaceOrientationMaskPortrait;
|
}
|
//穿山甲广告
|
- (void)setupBUAdSDK {
|
// [BUAdSDKManager set :NO];
|
// splash AD demo
|
|
[self addSplashAD];
|
}
|
|
- (void) initCSJAd:(BUCompletionHandler)completionHandler{
|
BUAdSDKConfiguration *configuration=[BUAdSDKConfiguration configuration];
|
configuration.appID=@"5096047";
|
configuration.coppa = @(0);
|
configuration.secretKey=@"buwan_ios!@";
|
[BUAdSDKManager startWithAsyncCompletionHandler:^(BOOL success, NSError *error) {
|
dispatch_async(dispatch_get_main_queue(),^{
|
[self initBUContent];
|
completionHandler(success,error);
|
});
|
}];
|
}
|
|
//初始化内容联盟
|
- (void)initBUContent{
|
// 初始化LCDSDK
|
LCDConfig *config = [LCDConfig new];
|
#if DEBUG
|
config.logLevel = LCDSDKLogLevelDebug;
|
#endif
|
// 请使用您的配置文件(例如SDK_Setting_5151488.json)初始化SDK,并确保配置文件已经作为Copy Bundle Resource引入工程
|
NSString *configPath = [[NSBundle mainBundle] pathForResource:@"SDK_Setting_5096047" ofType:@"json"];
|
|
[LCDManager startWithConfigPath:configPath config:config completion:^(LCDINITStatus initStatus, NSDictionary * _Nonnull userInfo) {
|
if (initStatus == LCDINITStatus_success) {
|
NSLog(@"初始化注册成功!");
|
} else {
|
NSLog(@"初始化注册失败,请重新注册");
|
}
|
}];
|
|
}
|
|
#pragma mark - Splash
|
- (void)addSplashAD {
|
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100);
|
|
self.viewBot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
|
self.viewBot .backgroundColor = [UIColor whiteColor];
|
[self.window.rootViewController.view addSubview:self.viewBot];
|
|
UIView *viewTop = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 100)];
|
[self.viewBot addSubview:viewTop];
|
|
UIView *views = [[UIView alloc] init];
|
views.backgroundColor = [UIColor whiteColor];
|
[self.viewBot addSubview:views];
|
views.sd_layout.leftEqualToView(self.viewBot).topSpaceToView(viewTop, 0).rightEqualToView(self.viewBot).bottomEqualToView(self.viewBot);
|
|
UIImageView *logos = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"375"]];
|
[views addSubview:logos];
|
logos.sd_layout.centerXEqualToView(views).centerYEqualToView(views).widthIs(KScreenW).heightIs(57);
|
|
self.splashAd = [[BUSplashAd alloc] initWithSlotID:@"887379201" adSize:CGSizeMake(frame.size.width, frame.size.height)];
|
|
//self.splashAd.tolerateTimeout = 10;
|
self.splashAd.delegate = self;
|
self.splashAd.tolerateTimeout=3.0;
|
float width = [UIScreen mainScreen].bounds.size.width;
|
float height = [UIScreen mainScreen].bounds.size.height;
|
UIImageView *imageview = [[UIImageView alloc] init];
|
|
CGFloat viewHeight = 0.0;
|
if (width == 320.0f && height<=480.0f) {
|
// iphone4 iphone4s 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x480"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
}else if (width ==320.0f && height==568.0f) {
|
// iphone5 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x568"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
} else if (width ==375.0f) {
|
// iphone6 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"375x667"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"375"]];
|
viewHeight = 63;
|
|
}else{
|
// iphone6 plus 上的default图片
|
_splash.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414x736"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414"]];
|
viewHeight = 69;
|
}
|
if (KIsiPhoneX) {
|
// _splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"1125x2436"]];
|
//imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414"]];
|
}
|
imageview.image = [UIImage imageNamed:@"375"];
|
|
UIWindow *keyWindow = self.window;
|
//self.startTime = CACurrentMediaTime();
|
[self.splashAd loadAdData];
|
//[keyWindow.rootViewController.view addSubview:self.splashAdView];
|
|
CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
|
|
//self.splashAdView.frame = CGRectMake(0, 0, KScreenW, screenH - viewHeight);
|
|
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, screenH - 100, KScreenW, 100)];
|
_bottomView.backgroundColor = [UIColor whiteColor];
|
|
imageview.frame = CGRectMake(0, 21.5, _bottomView.frame.size.width, 57);
|
[_bottomView addSubview:imageview];
|
|
[keyWindow addSubview:self.bottomView];
|
|
//self.splashAd.rootViewController = keyWindow.rootViewController;
|
}
|
|
|
- (void)loadAd {
|
BOOL res = [GDTSDKConfig registerAppId:GDTADkey];
|
if (res) {
|
|
}
|
self.splash = [[GDTSplashAd alloc] initWithPlacementId:GDTFullADid];
|
|
_splash.delegate = self;//设置代理
|
|
//根据iPhone设备不同设置不同的背景图
|
float width = [UIScreen mainScreen].bounds.size.width;
|
float height = [UIScreen mainScreen].bounds.size.height;
|
UIImageView *imageview = [[UIImageView alloc]init];
|
CGFloat viewHeight = 0.0;
|
if (width == 320.0f && height<=480.0f) {
|
// iphone4 iphone4s 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x480"]];
|
imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
}else if (width ==320.0f && height==568.0f) {
|
// iphone5 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"320x568"]];
|
imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"320"]];
|
viewHeight = 55;
|
|
}else if (width ==375.0f) {
|
// iphone6 上的default图片
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"375x667"]];
|
imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"375"]];
|
viewHeight = 63;
|
|
}else{
|
// iphone6 plus 上的default图片
|
_splash.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414x736"]];
|
imageview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"414"]];
|
viewHeight = 69;
|
}
|
if (KIsiPhoneX) {
|
_splash.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"1125x2436"]];
|
}
|
_splash.fetchDelay=5;//开屏拉取的时间,超时则放弃展示
|
// [_splash loadAdAndShowInWindow:self.window];//拉起并展示全屏广告
|
|
// [_splash loadAdAndShowInWindow:self.window withBottomView:[UIView new]];
|
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenH - viewHeight, KScreenW, viewHeight)];
|
imageview.frame = CGRectMake(0, 12, _bottomView.frame.size.width, _bottomView.frame.size.height - 6);
|
|
[_bottomView addSubview:imageview];
|
_bottomView.backgroundColor = [UIColor whiteColor];
|
UIView *loadView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, viewHeight)];
|
loadView.backgroundColor = [UIColor clearColor];
|
[_splash loadAdAndShowInWindow:self.window withBottomView:loadView];
|
[self.window addSubview:self.bottomView];
|
}
|
|
#pragma mark 信鸽推送
|
- (void)registerPush{
|
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
}
|
|
- (void)registerPushForIOS8{
|
//Types
|
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
|
|
//Actions
|
UIMutableUserNotificationAction *acceptAction = [[UIMutableUserNotificationAction alloc] init];
|
|
acceptAction.identifier = @"ACCEPT_IDENTIFIER";
|
acceptAction.title = @"Accept";
|
|
acceptAction.activationMode = UIUserNotificationActivationModeForeground;
|
acceptAction.destructive = NO;
|
acceptAction.authenticationRequired = NO;
|
|
//Categories
|
UIMutableUserNotificationCategory *inviteCategory = [[UIMutableUserNotificationCategory alloc] init];
|
|
inviteCategory.identifier = @"INVITE_CATEGORY";
|
[inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextDefault];
|
|
[inviteCategory setActions:@[acceptAction] forContext:UIUserNotificationActionContextMinimal];
|
|
NSSet *categories = [NSSet setWithObjects:inviteCategory, nil];
|
|
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:categories];
|
|
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
|
|
[[UIApplication sharedApplication] registerForRemoteNotifications];
|
}
|
|
|
-(void)loadMainView{
|
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
self.window.backgroundColor=[UIColor whiteColor];
|
[self.window makeKeyAndVisible];
|
|
|
|
// tabBarController.tabBar.itemPositioning = UITabBarItemPositioningFill;
|
|
// self.window.rootViewController = tabBarController;
|
//判断是否已经同意用户协议
|
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"privacy_and_protocol"]!=nil)
|
{
|
[self next];
|
} else {
|
[self showPrivacyAndProtocol];
|
}
|
|
}
|
|
#pragma mark 友盟集成
|
- (void)setUmeng{
|
|
[UMConfigure initWithAppkey:UmengKey channel:@"App Store"];
|
[UMConfigure setLogEnabled:NO];
|
|
// //友盟分享
|
// [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:YMWXKEY appSecret:YMWXSENT redirectURL:nil];//微信
|
//
|
// [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ appKey:YMQQKEY appSecret:YMQQSENT redirectURL:@"http://mobile.umeng.com/social"];//QQ
|
//
|
// [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina appKey:YMSinaKEY appSecret:YMSinaSecret redirectURL:@"https://sns.whalecloud.com/sina2/callback"];//新浪
|
}
|
|
#pragma mark 阿里百川
|
//-(void)setAliTrade{
|
// // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
|
// [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
|
// NSLog(@"成功");
|
// } failure:^(NSError *error) {
|
// NSLog(@"Init failed: %@", error.description);
|
// }];
|
//
|
// // 开发阶段打开日志开关,方便排查错误信息
|
// //默认调试模式打开日志,release关闭,可以不调用下面的函数
|
// [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];
|
//
|
// // 配置全局的淘客参数
|
// //如果没有阿里妈妈的淘客账号,setTaokeParams函数需要调用
|
// AlibcTradeTaokeParams *taokeParams = [[AlibcTradeTaokeParams alloc] init];
|
// taokeParams.pid = nil; //mm_XXXXX为你自己申请的阿里妈妈淘客pid
|
// [[AlibcTradeSDK sharedInstance] setTaokeParams:taokeParams];
|
//
|
// //设置全局的app标识,在电商模块里等同于isv_code
|
// //没有申请过isv_code的接入方,默认不需要调用该函数
|
// //[[AlibcTradeSDK sharedInstance] setISVCode:@"your_isv_code"];
|
//
|
// // 设置全局配置,是否强制使用h5
|
// [[AlibcTradeSDK sharedInstance] setIsForceH5:NO];
|
//}
|
|
#pragma mark 添加网络监测
|
- (void)NetworkMonitoring{
|
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
selector:@selector(reachabilityChang:)
|
name:AFNetworkingReachabilityDidChangeNotification
|
object:nil];
|
}
|
|
- (void) reachabilityChang: (NSNotification*)note {
|
switch ([AFNetworkReachabilityManager sharedManager].networkReachabilityStatus) {
|
case AFNetworkReachabilityStatusNotReachable:{//无网
|
[YTHsharedManger startManger].NetworkStatus = 0;
|
[self.bottomView removeFromSuperview];;
|
|
if ([self.YNetdelegateRecommend respondsToSelector:@selector(updateNet:)]) {
|
[self.YNetdelegateRecommend updateNet:0];
|
}
|
[self splashDisappear];
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWWAN:{//万维网
|
[YTHsharedManger startManger].NetworkStatus = 1;
|
if ([self.YNetdelegateRecommend respondsToSelector:@selector(updateNet:)]) {
|
[self.YNetdelegateRecommend updateNet:1];
|
}
|
}
|
break;
|
case AFNetworkReachabilityStatusReachableViaWiFi:{// 使用WiFi网络
|
[YTHsharedManger startManger].NetworkStatus = 2;
|
if ([self.YNetdelegateRecommend respondsToSelector:@selector(updateNet:)]) {
|
[self.YNetdelegateRecommend updateNet:2];
|
}
|
}
|
break;
|
case AFNetworkReachabilityStatusUnknown:{// 当前网络未知
|
[YTHsharedManger startManger].NetworkStatus = 3;
|
if ([self.YNetdelegateRecommend respondsToSelector:@selector(updateNet:)]) {
|
[self.YNetdelegateRecommend updateNet:3];
|
}
|
}
|
break;
|
}
|
[self fetchCommenConfig];
|
}
|
|
//开屏页消失
|
- (void) splashDisappear{
|
//加载首页广告
|
if(_vcRecommend!=nil)
|
{
|
if(_isFirstIn)
|
{
|
[_vcRecommend loadDataFromFile];
|
}
|
[_vcRecommend loadFullscreenVideoAd];
|
}
|
}
|
|
#pragma mark BUSplashAdDelegate
|
//- (void)splashAdDidLoad:(BUSplashAdView *)splashAd {
|
// if (splashAd.zoomOutView) {
|
// UIViewController *parentVC = [UIApplication sharedApplication].keyWindow.rootViewController;
|
// [parentVC.view addSubview:splashAd.zoomOutView];
|
// [parentVC.view bringSubviewToFront:splashAd];
|
// //Add this view to your container
|
// [parentVC.view insertSubview:splashAd.zoomOutView belowSubview:splashAd];
|
// splashAd.zoomOutView.rootViewController = parentVC;
|
// }
|
//}
|
|
///新版本回调
|
///
|
- (void)splashAdLoadFail:(BUSplashAd *)splashAd error:(BUAdError *)error{
|
[self.viewBot removeFromSuperview];
|
// [splashAd removeFromSuperview];
|
[self.bottomView removeFromSuperview];
|
self.bottomView = nil;
|
[self loadAd];
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
- (void)splashAdLoadSuccess:(BUSplashAd *)splashAd{
|
NSLog(@"splashAdLoadSuccess");
|
[splashAd showSplashViewInRootViewController:self.window.rootViewController];
|
}
|
|
- (void)splashAdRenderSuccess:(BUSplashAd *)splashAd{
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
- (void)splashAdDidClose:(nonnull BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
|
[self.viewBot removeFromSuperview];
|
//[splashAd removeFromSuperview];
|
[self.bottomView removeFromSuperview];
|
[self pbu_logWithSEL:_cmd msg:@""];
|
[self splashDisappear];
|
}
|
|
|
- (void)splashAdDidShow:(nonnull BUSplashAd *)splashAd {
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
|
- (void)splashAdViewControllerDidClose:(nonnull BUSplashAd *)splashAd {
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
|
- (void)splashAdWillShow:(nonnull BUSplashAd *)splashAd {
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
|
- (void)splashDidCloseOtherController:(nonnull BUSplashAd *)splashAd interactionType:(BUInteractionType)interactionType {
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
|
- (void)splashVideoAdDidPlayFinish:(nonnull BUSplashAd *)splashAd didFailWithError:(nonnull NSError *)error {
|
[self pbu_logWithSEL:_cmd msg:@""];
|
}
|
|
|
- (void)pbu_logWithSEL:(SEL)sel msg:(NSString *)msg {
|
|
}
|
|
|
#pragma mark -GDTSplashAdDelegate
|
-(void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd
|
{
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
-(void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
|
{
|
self.bottomView.hidden = YES;
|
[self.bottomView removeFromSuperview];
|
NSLog(@"%s%@",__FUNCTION__,error);
|
[self splashDisappear];
|
}
|
|
-(void)splashAdClicked:(GDTSplashAd *)splashAd
|
{
|
self.bottomView.hidden = YES;
|
[self.bottomView removeFromSuperview];
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
-(void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd
|
{
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
-(void)splashAdWillClosed:(GDTSplashAd *)splashAd
|
{
|
self.bottomView.hidden = YES;
|
[self.bottomView removeFromSuperview];
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
-(void)splashAdClosed:(GDTSplashAd *)splashAd
|
{
|
NSLog(@"splash-ad gdt close");
|
NSLog(@"%s",__FUNCTION__);
|
self.bottomView.hidden = YES;
|
[self.bottomView removeFromSuperview];
|
_splash = nil;
|
[self splashDisappear];
|
}
|
|
- (void)splashAdWillPresentFullScreenModal:(GDTSplashAd *)splashAd
|
{
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
- (void)splashAdDidPresentFullScreenModal:(GDTSplashAd *)splashAd
|
{
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
- (void)splashAdWillDismissFullScreenModal:(GDTSplashAd *)splashAd
|
{
|
self.bottomView.hidden = YES;
|
[self.bottomView removeFromSuperview];
|
|
NSLog(@"%s",__FUNCTION__);
|
|
}
|
-(void)splashAdDidDismissFullScreenModal:(GDTSplashAd *)splashAd
|
{
|
|
NSLog(@"%s",__FUNCTION__);
|
}
|
|
|
@end
|