admin
2023-04-21 57e30bc2584b92ce3da3821bd0f6e040f2ad28df
BuWanVideo2.0/AppDelegate.m
@@ -34,6 +34,7 @@
#import "DYDrawVideoController.h"
#import "DYNewsController.h"
#import "DYNovelController.h"
#import "CustomIOSAlertView.h"
#import <UMCommon/UMCommon.h>
//#import <UMShare/UMShare.h>
@@ -46,7 +47,6 @@
//内容联盟
#import <LCDSDK/LCDSDK.h>
#import <BDNovelPublicConfig.h>
#define LECUsedBundleID   @"com.yeshi.buwanshequ.ios"
@@ -62,8 +62,11 @@
@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
@@ -74,19 +77,24 @@
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    //设置状态栏的字体颜色
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    _inited=false;
    TOCK;
    return YES;
}
- (void) initSDK:(BUCompletionHandler)completionHandler{
    [self requestIDFA];
    //添加网络监测
    [self NetworkMonitoring];
    [self fetchCommenConfig];
    //集成友盟
    [self setUmeng];
    //[MobClick setLogEnabled:YES];
    
    //集成穿山甲内容联盟
    [self initCSJAd];
    [self initBUContent];
    [self initCSJAd:completionHandler];
    //广点通注册
    [GDTSDKConfig registerAppId:GDTADkey];
    
    
    [[IQKeyboardManager sharedManager] setEnable:YES];
@@ -104,20 +112,214 @@
    }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 loadMainView];
            [self initFinish];
    } else {
        //获取Uid
        [self getUid];
    }
    }];
}
    TOCK;
    return YES;
- (void) initFinish{
    [self setupBUAdSDK];
}
- (void)requestIDFA {
@@ -131,6 +333,8 @@
    }
}
- (void)fetchCommenConfig {
    NSMutableDictionary *parms = [[NSMutableDictionary alloc] init];
    [parms setObject:@"getConfig" forKey:@"Method"];
@@ -138,7 +342,10 @@
        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{
        }
    }];
}
@@ -172,6 +379,7 @@
- (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) {
@@ -245,13 +453,13 @@
            [uid setValue:datasourceDic[@"ShowAd"] forKey:@"ShowAd"];//是否在福利社的地方弹好评的框,1为弹,0为不弹
            [uid synchronize];
            //加载主视图
            [self loadMainView];
            [self initFinish];
        }else{
            //判断当前用户是否还保存有Uid,如果没有,要提醒用户暂时不能使用
            if ([YTHsharedManger startManger].Uid == nil) {
                //提醒用户暂不能使用,请检查网络
                //还是允许用户进入
                [self loadMainView];
                [self initFinish];
            }
        }
    }];
@@ -271,22 +479,17 @@
    [self addSplashAD];
}
- (void) initCSJAd{
    //optional
    //GDPR 0 close privacy protection, 1 open privacy protection
    [BUAdSDKManager setGDPR:0];
    //optional
    //Coppa 0 adult, 1 child
    [BUAdSDKManager setCoppa:0];
#if DEBUG
    // Whether to open log. default is none.
    [BUAdSDKManager setLoglevel:BUAdSDKLogLevelDebug];
    //    [BUAdSDKManager setDisableSKAdNetwork:YES];
#endif
    //BUAdSDK requires iOS 9 and up
    //
    [BUAdSDKManager setAppID:@"5096047"];
- (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);
        });
    }];
}
//初始化内容联盟
@@ -307,58 +510,6 @@
        }
    }];
    
    //初始化小说
    [BDNovelPublicConfig startWithConfig:^(BDNovelPublicConfig * _Nonnull makeConfig) {
          /*
          开发者在内容输出模块绑定对应的应用,会自动生成章前、章间、激励视屏、banner、首页插屏等代码位,只需将sdk配置的json文件拷贝到项目中即可
          */
           makeConfig.personalRecommendEnabled = YES;
            /*
           novelCoverFontSize // 首页以及封面大字版,没有设置阅读器正文大小时,默认4挡;
           novelContentFontSize // 阅读器正文字体大小设置
           */
           makeConfig.novelCoverFontSize = BDNovelFontSizeNormal;
           makeConfig.configPath = [[NSBundle mainBundle] pathForResource:@"SDK_Setting_5096047" ofType:@"json"];//pathForResource为SDK动态下发json配置文件的路径
          makeConfig.autoConfigTrack = YES; //如果原本app已经接入DataRanges,请设置NO
          makeConfig.logger = ^(NSString * _Nullable log) {
              NSLog(@"%@", log); //log以【Tomato-Novel】开头
          };
        if(@available(iOS 13.0,*))
        {
            makeConfig.userInterfaceStyleCallback = ^{
              return [self.class novelUIUserInterfaceStyle];
            };
        }
      } completion:^(NSString * _Nullable error) {
      }];
}
+ (BDNovelUIUserInterfaceStyle)novelUIUserInterfaceStyle
{
    /*
     暗色模式,开关在DebugVC里面
     */
    static NSString *const kBDNovelDarkMode = @"深色模式测试";
    NSInteger novelResultNumber = [NSUserDefaults.standardUserDefaults integerForKey:kBDNovelDarkMode];
    if (novelResultNumber == 0) {
        return BDNovelUIUserInterfaceStyleUnspecified;
    } else if (novelResultNumber == 1) {
        return BDNovelUIUserInterfaceStyleDark;
    } else {
        return BDNovelUIUserInterfaceStyleLight;
    }
//    return BDNovelUIUserInterfaceStyleUnspecified;
}
#pragma mark - Splash
@@ -542,56 +693,18 @@
    self.window.backgroundColor=[UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    _vcRecommend = [[RecommendMainController alloc]init];
    _vcRecommend.tabBarItem.image = [[UIImage imageNamed:@"nav_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    _vcRecommend.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_home_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController *nrecommendVC = [[UINavigationController alloc]initWithRootViewController:_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];
    DYNewsController *disVC = [[DYNewsController alloc]init];
    disVC.tabBarItem.image = [[UIImage imageNamed:@"nav_discover"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    disVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_discover_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController *ndisVC = [[UINavigationController alloc]initWithRootViewController:disVC];
    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];
    DYNovelController *novelVC = [[DYNovelController alloc]init];
    novelVC.tabBarItem.image = [[UIImage imageNamed:@"nav_novel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    novelVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"nav_novel_highlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController *nnovelVC = [[UINavigationController alloc]initWithRootViewController:novelVC];
    //信息流
    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];
    SJTabbarViewController *tabBarController = [[SJTabbarViewController alloc]init];
    tabBarController.viewControllers = @[nrecommendVC,ndrawVC,ndisVC,nmineVC];//nnovelVC
    tabBarController.tabBar.tintColor = YTHColor(0, 82, 246);
    tabBarController.tabBar.unselectedItemTintColor=YTHColor(153, 153, 153);
    [tabBarController.tabBar setClipsToBounds:YES];
    tabBarController.tabBar.opaque = YES;
    NSMutableDictionary *attr3=[NSMutableDictionary dictionary];
    attr3[NSFontAttributeName]=[UIFont systemFontOfSize:10];
    [[UITabBarItem appearance]setTitleTextAttributes:attr3 forState:UIControlStateNormal];
    //    tabBarController.tabBar.itemPositioning = UITabBarItemPositioningFill;
    
    self.window.rootViewController = tabBarController;
    [self setupBUAdSDK];
    //添加开屏广告
    NSLog(@"");
//    self.window.rootViewController = tabBarController;
    //判断是否已经同意用户协议
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"privacy_and_protocol"]!=nil)
    {
        [self next];
    } else {
        [self showPrivacyAndProtocol];
    }
    
}
@@ -679,6 +792,7 @@
        }
            break;
    }
    [self fetchCommenConfig];
}
//开屏页消失
@@ -686,6 +800,10 @@
    //加载首页广告
    if(_vcRecommend!=nil)
    {
        if(_isFirstIn)
        {
            [_vcRecommend loadDataFromFile];
        }
        [_vcRecommend loadFullscreenVideoAd];
    }
}