AppDelegate.m 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272
  1. //
  2. // AppDelegate.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 16/4/12.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. #import "AppDelegate.h"
  8. #import "UIImageView+WebCache.h"
  9. #import "SDWebImageManager.h"
  10. #import "NewFeatureController.h"
  11. #import <UMPush/UMessage.h>
  12. #import <UMCommon/UMCommon.h>
  13. #import <UMShare/UMShare.h>
  14. //#import "UMessage.h"
  15. //#import "UMSocialWechatHandler.h"
  16. #import "BogoNewsTabNumModel.h"
  17. #import "AppModel.h"
  18. #import <AudioToolbox/AudioToolbox.h>
  19. #import "CustomMessageModel.h"
  20. #import "BogoJHLogin.h"
  21. #import "GTMBase64.h"
  22. #import "UserModel.h"
  23. #import "dataModel.h"
  24. #import <UserNotifications/UserNotifications.h>
  25. #import "AdJumpViewModel.h"
  26. #import "FLAnimatedImage.h"
  27. #import "BGInterface.h"
  28. #import "SHomePageVC.h"
  29. //#import <Bugly/Bugly.h>
  30. //#import <TXLiteAVSDK_Professional/TXLiveBase.h>
  31. #import <TXLiteAVSDK_Professional/TXUGCBase.h>
  32. //#import "OpenInstallSDK.h"
  33. #import "ViewController.h"
  34. #import <XHLaunchAd/XHLaunchAd.h>
  35. #import "MGAdvertViewController.h"
  36. #import "BogoNetworkKit.h"
  37. #import <UMLink/UMLink.h>
  38. #import "IAPManager.h"
  39. //BogoGuideViewController
  40. //#import <TXLiteAVSDK_UGC/TXLiveBase.h>
  41. #import "BogoShopKit.h"
  42. //#import <FBSDKCoreKit/FBSDKCoreKit.h>
  43. #import "BogoPrivacyPopView.h"
  44. #import "BogoGuildKit.h"
  45. #import "SIdentificationVC.h"
  46. //导入UMAPM的OC的头文件
  47. #import <UMAPM/UMLaunch.h>
  48. #import <UMAPM/UMCrashConfigure.h>
  49. #import <UMAPM/UMAPMConfig.h>
  50. #import <PushKit/PushKit.h>
  51. #import <UserNotifications/UserNotifications.h>
  52. //#import <AudioToolbox/AudioToolbox.h>
  53. //#import <CallKit/CallKit.h>
  54. #import "TRTCCallingUtils.h"
  55. #import "AudioChatTool.h"
  56. #import <TIMPush/TIMPush.h>
  57. #import <TUIVoIPExtension/TUIVoIPExtension-umbrella.h>
  58. #import <TUICallEngine/TUICallEngine.h>
  59. #import "AudioChatViewController.h"
  60. @import FirebaseCore;
  61. @import GoogleSignIn;
  62. #define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
  63. #define _IPHONE80_ 80000
  64. #define SavePath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject stringByAppendingPathComponent:@"user.archive"]
  65. #define kAdImgViewLoadFromNetTimes 1 // 启动广告图从网络下载的最大时间,如果超过该时间则该次启动不显示
  66. static SystemSoundID shake_sound_male_id = 0;
  67. @import FirebaseCore;
  68. @import FirebaseFirestore;
  69. @import FirebaseAuth;
  70. @interface AppDelegate ()<NewFeatureControllerDelegate,NewFeatureControllerDatasourse,QMapLocationViewDelegate,XHLaunchAdDelegate,MobClickLinkDelegate,UITextFieldDelegate,BogoPrivacyPopViewDelegate,BMKGeneralDelegate,UNUserNotificationCenterDelegate,TIMPushDelegate,TIMPushListener>
  71. {
  72. NetHttpsManager *_httpsManager;
  73. MBProgressHUD *_HUD;
  74. QMapLocationView *_mapLocationView; // 腾讯地图
  75. IMALoginParam *_loginParam; // 判断是否登录
  76. FLAnimatedImageView *_advImgView;
  77. HMHotBannerModel *_adModel;
  78. BOOL _isAdTouched; // 广告图是否能够点击
  79. NSString *_pboardString; // 粘贴板的字符串
  80. NSDictionary *_pushInfoDict;
  81. BOOL _isEnterForeground; // YES:在前台,NO:在后台或程序还没有启动
  82. BOOL _isFirstLoad; // YES:第一次启动
  83. BOOL _isFirstLoadInit; // 是否第一次加载初始化接口
  84. BOOL _isShowAdImgViewIng; // 是否正在显示启动广告图
  85. NSInteger _currentMainUrlIndex; // 当前域名对应备用域名数组的所在下标
  86. NSInteger _netChangedTimes; // 网络变化次数
  87. NSTimeInterval _willResignActiveDate; // 将要进入后台的时间(秒)
  88. }
  89. @property (nonatomic, strong) GlobalVariables *BuguLive;
  90. @property (nonatomic, assign) BOOL isShowAdImgView; // 是否需要显示启动广告图
  91. @property (nonatomic, copy) NSString *homePageUserId; // 私密直播关闭之后用户的userID,目的进入主页看回看
  92. @property (nonatomic, strong) UserModel *pushUserModel;
  93. @property(nonatomic, strong) LivingModel *model;
  94. @property(nonatomic, strong) NSArray *modelArr;
  95. @property(nonatomic, copy) NSString *password;
  96. @property(nonatomic, strong) NSDictionary *launchOptions;
  97. @property(nonatomic, strong) BogoPrivacyPopView *privacyPopView;
  98. @property(nonatomic, strong) NSDictionary *responseJson;
  99. @property (nonatomic,assign) BOOL isAlreadyPushLoginVC;
  100. @property (nonatomic,strong) NSDictionary * alllaunchOptions;
  101. @end
  102. @implementation AppDelegate
  103. + (instancetype)sharedAppDelegate
  104. {
  105. return (AppDelegate *)[UIApplication sharedApplication].delegate;
  106. }
  107. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  108. {
  109. self.alllaunchOptions = launchOptions;
  110. [self switchLanguage];
  111. [FIRApp configure];
  112. #ifdef __IPHONE_11_0
  113. if (@available(ios 11.0,*))
  114. {
  115. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  116. UITableView.appearance.estimatedRowHeight = 0;
  117. UITableView.appearance.estimatedSectionFooterHeight = 0;
  118. UITableView.appearance.estimatedSectionHeaderHeight = 0;
  119. }
  120. #endif
  121. if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_0)
  122. {
  123. NSLog(@"NSFoundationVersionNumber==%d",(int)NSFoundationVersionNumber);
  124. }
  125. if (@available(iOS 13.0, *)) {
  126. UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
  127. [appearance configureWithOpaqueBackground];
  128. appearance.backgroundColor = kWhiteColor;
  129. [[UINavigationBar appearance] setStandardAppearance:appearance];
  130. [[UINavigationBar appearance] setScrollEdgeAppearance:appearance];
  131. } else {
  132. // Fallback on earlier versions
  133. [[UINavigationBar appearance] setBarTintColor:kWhiteColor];
  134. [[UINavigationBar appearance] setTranslucent:NO];
  135. }
  136. [TIMPushManager addPushListener:self];
  137. // [V2TIMManager.sharedInstance setAPNSListener:self];
  138. // [[V2TIMManager sharedInstance] setConversationListener:self];
  139. // [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  140. // // iOS 10之前
  141. // UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
  142. // [application registerUserNotificationSettings:settings];
  143. //
  144. // // iOS 10
  145. // UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  146. // [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error)
  147. // {
  148. // if (!error)
  149. // {
  150. // NSLog(@"request authorization succeeded!");
  151. // }
  152. // }];
  153. //
  154. // [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  155. // NSLog(@"%@",settings);
  156. // }];
  157. _sus_window = [[SuspenionWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
  158. [_sus_window makeKeyWindow];
  159. _sus_window.hidden = YES;
  160. //iOS11以后iPhone X相册偏移适配
  161. if (@available(iOS 11.0, *)){
  162. [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
  163. }
  164. // [TXUGCBase setLicenceURL:@"http://license.vod2.myqcloud.com/license/v1/9d11149e7ab9409d37960b76d72513d3/TXUgcSDK.licence" key:@"c42c151886efa4877920bcf60d364ad0"];
  165. // 用来延时遮盖,等异步请求初始化接口成功后替换掉
  166. UIViewController *tmpController = [[UIViewController alloc]init];
  167. UIImageView *tmpImgView = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
  168. tmpImgView.contentMode = UIViewContentModeScaleAspectFill;
  169. tmpImgView.clipsToBounds = YES;
  170. [tmpImgView setImage:[UIImage imageNamed:@"lg_bg"]];
  171. [tmpController.view addSubview:tmpImgView];
  172. self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  173. self.window.rootViewController = tmpController;
  174. [self.window makeKeyAndVisible];
  175. _isFirstLoad = YES;
  176. _isShowAdImgView = YES;
  177. self.BuguLive = [GlobalVariables sharedInstance];
  178. _httpsManager = [NetHttpsManager manager];
  179. _pushInfoDict = [NSDictionary dictionary];
  180. // 异步加载初始化接口
  181. _isFirstLoadInit = YES;
  182. self.launchOptions = launchOptions;
  183. [self asyncInit];
  184. // 网络监听
  185. [self performSelector:@selector(startMonitor) withObject:nil afterDelay:3];
  186. // // 配置第三方sdk
  187. // [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
  188. // [self configureOhter:launchOptions];
  189. // [TXUGCBase setLicenceURL:@"http://license.vod2.myqcloud.com/license/v1/9d11149e7ab9409d37960b76d72513d3/TXUgcSDK.licence" key:@"c42c151886efa4877920bcf60d364ad0"];
  190. if (@available(iOS 11, *)) {
  191. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  192. }
  193. // [OpenInstallSDK initWithDelegate:self];
  194. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveOSSNoti) name:kFDOSSManagerSendNoti object:nil];
  195. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToLive:) name:GoToLiveFromShopKit object:nil];
  196. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToUserPage:) name:GoToUserPageFromShopKit object:nil];
  197. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToUserMsgVC:) name:GoToUserMsgVCShopKit object:nil];
  198. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterLoginUI) name:@"enterLoginUI" object:nil];
  199. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToUserPage:) name:kNotificationGuildToUserPageKey object:nil];
  200. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(goToAuth) name:kNotificationGuildToAuthKey object:nil];
  201. #warning Facebook登录,暂时注释
  202. //facebook登录
  203. // [[FBSDKApplicationDelegate sharedInstance] application:application
  204. // didFinishLaunchingWithOptions:launchOptions];
  205. // [[FBSDKSettings sharedSettings] setAppID:@"533941785070370"];
  206. //// [FBSDKSettings setAppID:@"1689775438036292"];
  207. //解决第一次点击textfield卡顿问题
  208. [self textfieldResponderRemove];
  209. [[IAPManager sharedManager] checkUnfinishedTransactions];
  210. return YES;
  211. }
  212. ////配置离线消息推送
  213. -(int)businessID{
  214. //16706 voip
  215. // 16705 apns
  216. return 16705;
  217. }
  218. - (BOOL)onRemoteNotificationReceived:(NSString *)notice{
  219. return NO;
  220. }
  221. //收到 Push 消息
  222. -(void)onRecvPushMessage:(TIMPushMessage *)message{
  223. NSLog(@"%@",message.ext);
  224. //在线时来电电话
  225. //点击通知后来电电话
  226. NSDictionary *dic = [TRTCCallingUtils jsonSring2Dictionary:message.ext];
  227. // 视频
  228. if ([dic[@"entity"][@"type"] isEqual: @(MSG_PRIVATE_CallVideo)] ){
  229. //
  230. if (![[BGBaseAppDelegate sharedAppDelegate].topViewController isKindOfClass:[VideoChatVC class]]){
  231. [self judjeLaunchSuccess:dic[@"makedat"]];
  232. }
  233. // [self playCustomSound];//播放自定义推送声音
  234. }
  235. //语音
  236. if ( [dic[@"entity"][@"type"] isEqual: @(MSG_PRIVATE_CallAudio)]){
  237. if (![[BGBaseAppDelegate sharedAppDelegate].topViewController isKindOfClass:[AudioChatViewController class]]){
  238. [self judjeLaunchSuccess:dic[@"makedat"]];
  239. }
  240. }
  241. // [self playCustomSound];//播放自定义推送声音
  242. // [AudioChatTool.shareInstance receivePushVoipMsgWithNotification:dic[@"voipdic"]];
  243. }
  244. -(void)onNotificationClicked:(NSString *)ext{
  245. NSLog(@"%@",ext);
  246. //点击通知后来电电话
  247. NSDictionary *dic = [TRTCCallingUtils jsonSring2Dictionary:ext];
  248. if ([dic[@"entity"][@"type"] isEqual: @(MSG_PRIVATE_CallVideo)]){
  249. // [self judjeLaunchSuccess:dic[@"makedat"]];
  250. // [self playCustomSound];//播放自定义推送声音
  251. }else{
  252. UITabBarController *tabBars = [BGTabBarController sharedInstance];
  253. tabBars.selectedIndex = 3;
  254. }
  255. }
  256. -(void)navigateToBuiltInChatViewController:(NSString *)userID groupID:(NSString *)groupID{
  257. NSLog(@"%@",userID);
  258. UITabBarController *tabBars = [BGTabBarController sharedInstance];
  259. tabBars.selectedIndex = 3;
  260. // BGConversationServiceController *chatvc = [BGConversationServiceController makeChatVCWith:oneobj isHalf:NO];
  261. // chatvc.dic = @{
  262. // @"mHead_image": oneobj.mHead_image,
  263. // @"mUser_id": @(oneobj.mUser_id)
  264. // };
  265. // [[AppDelegate sharedAppDelegate] pushViewController:chatvc animated:YES];
  266. }
  267. - (void)switchLanguage {
  268. //如果设置过语言
  269. NSString * preferredLang = [[NSUserDefaults standardUserDefaults] objectForKey:KAppLanguage];
  270. NSLog(@" 1当前语言 = %@",preferredLang);
  271. if ([NSString isEmpty:preferredLang] == NO) {
  272. //阿拉伯语
  273. if([preferredLang isEqualToString:@"ar"]) {
  274. [UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  275. [UISearchBar appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  276. [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  277. }
  278. [[LocalizationSystem sharedLocalSystem] setLanguage:preferredLang];
  279. }else{
  280. //如果没有设置语言就跟随本地
  281. //获得当前语言
  282. NSArray *languages = [NSLocale preferredLanguages];
  283. NSString *systemLanguage = [languages objectAtIndex:0];
  284. NSLog(@"2 -1当前语言 = %@",systemLanguage);
  285. NSString * currentLabguage = @"";
  286. if([systemLanguage hasPrefix:@"zh-Hans"]){
  287. currentLabguage = @"zh-Hans";
  288. }else if([systemLanguage hasPrefix:@"th"]){
  289. //泰语
  290. currentLabguage = @"th";
  291. }else if([systemLanguage hasPrefix:@"zh-Hant"]){
  292. //中文繁体
  293. currentLabguage = @"zh-Hant";
  294. }else if([systemLanguage hasPrefix:@"vi"]){
  295. //越南语
  296. currentLabguage = @"vi";
  297. }else if([systemLanguage hasPrefix:@"ja"]){
  298. //日语
  299. currentLabguage = @"ja";
  300. }else if([systemLanguage hasPrefix:@"ar"]){
  301. //阿拉伯语
  302. currentLabguage = @"ar";
  303. [UIView appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  304. [UISearchBar appearance].semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  305. [[UINavigationBar appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  306. }else{
  307. //默认英语
  308. currentLabguage = @"en";
  309. }
  310. NSLog(@"3当前语言 = %@",currentLabguage);
  311. [[LocalizationSystem sharedLocalSystem] setLanguage:currentLabguage];
  312. }
  313. }
  314. - (void)goToAuth{
  315. SIdentificationVC *identificationVC = [[SIdentificationVC alloc]init];
  316. identificationVC.user_id = [GlobalVariables sharedInstance].userModel.user_id;
  317. identificationVC.sexString = [GlobalVariables sharedInstance].userModel.sex;
  318. identificationVC.nameString = [GlobalVariables sharedInstance].userModel.nick_name;
  319. [[AppDelegate sharedAppDelegate] pushViewController:identificationVC animated:YES];
  320. }
  321. - (void)doAfterAgreePrivacy{
  322. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
  323. //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  324. //2.设为3即表示:启动页将停留3s等待服务器返回广告数据,3s内等到广告数据,将正常显示广告,否则将不显示
  325. //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  326. //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  327. [XHLaunchAd setWaitDataDuration:3];
  328. if (self.responseJson)
  329. {
  330. [self setLaunchAboutViewWithDic:self.responseJson];
  331. [self setFirstLoad:self.responseJson];
  332. }
  333. BogoNetworkInitModel *indexModel = [BogoNetworkInitModel mj_objectWithKeyValues:self.responseJson];
  334. [[BogoNetwork shareInstance] saveIndexModel:indexModel];
  335. [self.BuguLive storageAppCurrentMainUrl:self.BuguLive.currentDoMianUrlStr];
  336. [self configThird];
  337. }
  338. - (void)configThird{
  339. // 配置第三方sdk
  340. [self configureOhter:self.launchOptions];
  341. // [TXUGCBase setLicenceURL:@"http://license.vod2.myqcloud.com/license/v1/9d11149e7ab9409d37960b76d72513d3/TXUgcSDK.licence" key:@"c42c151886efa4877920bcf60d364ad0"];
  342. // 地图定位
  343. _mapLocationView = [QMapLocationView sharedInstance];
  344. _mapLocationView.delegate = self;
  345. [_mapLocationView startLocate];
  346. [SVProgressHUD setMinimumDismissTimeInterval:1];
  347. if (@available(iOS 11, *)) {
  348. UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
  349. }
  350. // [OpenInstallSDK initWithDelegate:self];
  351. #pragma mark - 暂时注释
  352. // [[FBSDKApplicationDelegate sharedInstance] application:[UIApplication sharedApplication] didFinishLaunchingWithOptions:self.launchOptions];
  353. // [Bugly startWithAppId:BUGLY_APP_ID config:nil];
  354. [self initUMPushOptions:self.alllaunchOptions];
  355. }
  356. - (void)goToLive:(NSNotification *)noti{
  357. NSDictionary *dict = (NSDictionary *)noti.object;
  358. LivingModel *model = [LivingModel mj_objectWithKeyValues:dict];
  359. model.room_id = model.id.intValue;
  360. [self pushToLiveController:model modelArr:@[model] isFirstJump:YES];
  361. }
  362. - (void)goToUserPage:(NSNotification *)noti{
  363. SHomePageVC *pageVC = [[SHomePageVC alloc]init];
  364. pageVC.user_id = (NSString *)noti.object;
  365. [[AppDelegate sharedAppDelegate] pushViewController:pageVC animated:YES];
  366. }
  367. -(void)goToUserMsgVC:(NSNotification *)noti{
  368. // NSString *userID = (NSString *)noti.object;
  369. // @property(nonatomic, strong) BogoCommodityDetailModel *model;
  370. BogoCommodityDetailModel *model = (BogoCommodityDetailModel *)noti.object;
  371. SFriendObj* chattag = [[SFriendObj alloc]initWithUserId:[model.uid intValue]];
  372. chattag.mNick_name = model.shop.nick_name;
  373. chattag.mHead_image = StrValid(model.shop.logo) ? model.shop.logo : model.icon;
  374. BGConversationServiceController* chatvc = [BGConversationServiceController makeChatVCWith:chattag];
  375. [[AppDelegate sharedAppDelegate] pushViewController:chatvc animated:YES];
  376. }
  377. #pragma mark - BogoShopKit进入直播间
  378. //输入密码
  379. -(void)clickPasswordActionDelegateWithPassWord:(NSString *)password{
  380. WeakSelf
  381. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请输入房间密码")preferredStyle:UIAlertControllerStyleAlert];
  382. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  383. textField.placeholder = ASLocalizedString(@"请输入密码");
  384. textField.delegate = self;
  385. textField.keyboardType = UIKeyboardTypeNumberPad;
  386. [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
  387. }];
  388. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  389. }];
  390. [alertController addAction:actionCacel];
  391. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  392. NSString *md5Str = [[NSString md5String:self.password] uppercaseString];
  393. //转化为大写
  394. NSLog(@"%@",md5Str);
  395. NSLog(@"%@",password);
  396. if ([md5Str isEqualToString:self.model.password]) {
  397. [self pushToLiveController:_model modelArr:_modelArr isFirstJump:NO];
  398. }else{
  399. [FanweMessage alertHUD:ASLocalizedString(@"密码不正确")];
  400. }
  401. }];
  402. [alertController addAction:actionConfirm];
  403. UIViewController *top = [self topViewController];
  404. [top presentViewController:alertController animated:YES completion:nil];
  405. }
  406. -(void)textFieldDidChangeSelection:(UITextField *)textField{
  407. self.password = textField.text;
  408. }
  409. -(void)textFieldDidChange:(UITextField *)textField{
  410. self.password = textField.text;
  411. }
  412. #pragma mark NewestViewController跳转到直播
  413. -(void)pushToLiveController:(LivingModel *)model modelArr:(NSArray *)modelArr isFirstJump:(BOOL)isFirstJump
  414. {
  415. _model = model;
  416. _modelArr = modelArr;
  417. if (![BGUtils isNetConnected])
  418. {
  419. return;
  420. }
  421. if (isFirstJump) {
  422. self.password = @"";
  423. }
  424. if (![BGUtils isBlankString:model.password] && isFirstJump) {
  425. [self clickPasswordActionDelegateWithPassWord:model.password];
  426. return;
  427. }
  428. [[GlobalVariables sharedInstance].newestLivingMArray removeAllObjects];
  429. [[GlobalVariables sharedInstance].newestLivingMArray addObject:model];
  430. if ([self checkUser:[IMAPlatform sharedInstance].host])
  431. {
  432. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  433. item.chatRoomId = model.group_id;
  434. item.avRoomId = model.room_id;
  435. item.title = StringFromInt(model.room_id);
  436. item.vagueImgUrl = model.head_image;
  437. item.is_voice = model.is_voice;
  438. TCShowUser *showUser = [[TCShowUser alloc]init];
  439. showUser.uid = model.user_id;
  440. showUser.avatar = model.head_image;
  441. item.host = showUser;
  442. if (model.live_in == FW_LIVE_STATE_ING)
  443. {
  444. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  445. }
  446. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  447. // {
  448. // item.liveType = FW_LIVE_TYPE_RELIVE;
  449. // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
  450. // }
  451. if ([LiveCenterManager sharedInstance].itemModel) {
  452. [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLiveRoomNotification" object:nil];
  453. }
  454. [LiveCenterManager sharedInstance].itemModel=item;
  455. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  456. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:modelArr isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  457. }];
  458. }
  459. else
  460. {
  461. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  462. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  463. } completion:^{
  464. }];
  465. }
  466. }
  467. - (BOOL)checkUser:(id<IMHostAble>)user
  468. {
  469. if (![user conformsToProtocol:@protocol(AVUserAble)])
  470. {
  471. return NO;
  472. }
  473. return YES;
  474. }
  475. - (void)recieveOSSNoti{
  476. NSMutableDictionary * mDict = [NSMutableDictionary dictionary];
  477. [mDict setObject:@"app" forKey:@"ctl"];
  478. [mDict setObject:@"aliyun_sts" forKey:@"act"];
  479. [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  480. [[NSNotificationCenter defaultCenter] postNotificationName:kFDOSSManagerRecieveNoti object:responseJson];
  481. } FailureBlock:^(NSError *error){
  482. }];
  483. }
  484. -(void)textfieldResponderRemove{
  485. UITextField *lagFreeField = [[UITextField alloc] init];
  486. [self.window addSubview:lagFreeField];
  487. [lagFreeField becomeFirstResponder];
  488. [lagFreeField resignFirstResponder];
  489. [lagFreeField removeFromSuperview];
  490. }
  491. #pragma mark 配置第三方sdk
  492. - (void)configureOhter:(NSDictionary *)launchOptions
  493. {
  494. [TIMManager sharedInstance];
  495. // 设置ILiveSDK日志级别
  496. // [[TIMManager sharedInstance] initLogSettings:YES logPath:[[TIMManager sharedInstance] getLogPath]];
  497. // [[TIMManager sharedInstance] setLogLevel:TIM_LOG_NONE];
  498. NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  499. NSString *version = infoDict[@"CFBundleShortVersionString"];
  500. NSString *build = infoDict[@"CFBundleVersion"];
  501. [UMCrashConfigure setAppVersion:version buildVersion:build];
  502. /* 设置友盟appkey */
  503. #if DEBUG
  504. [UMConfigure setLogEnabled:YES];
  505. [UMConfigure initWithAppkey:UmengKey channel:@"Debug"]; // 新版
  506. #else
  507. [UMConfigure initWithAppkey:UmengKey channel:@"App Store"]; // 新版
  508. #endif
  509. // [[UMSocialManager defaultManager] setUmSocialAppkey:UmengKey];//旧版
  510. /* 设置微信的appKey和appSecret */
  511. // [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession
  512. // appKey:WeixinAppId
  513. // appSecret:WeixinSecret
  514. // redirectURL:@"http://mobile.umeng.com/social"];
  515. // /* 设置分享到QQ互联的appID
  516. // * U-Share SDK为了兼容大部分平台命名,统一用appKey和appSecret进行参数设置,而QQ平台仅需将appID作为U-Share的appKey参数传进即可。
  517. // */
  518. // [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ
  519. // appKey:QQAppId
  520. // appSecret:QQSecret
  521. // redirectURL:@"http://mobile.umeng.com/social"];
  522. // /* 设置新浪的appKey和appSecret */
  523. // [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina
  524. // appKey:SinaAppId
  525. // appSecret:SinaSecret
  526. // redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
  527. /* 设置Facebook的appKey和appSecret */
  528. [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Facebook
  529. appKey:@"533941785070370"
  530. appSecret:@""
  531. redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
  532. #warning Facebook登录,暂时注释
  533. // [[FBSDKApplicationDelegate sharedInstance] initializeSDK];
  534. // [[FBSDKSettings sharedSettings] setAppID:@"533941785070370"];
  535. //// [FBSDKSettings setAppID:@"1689775438036292"];
  536. // 腾讯地图
  537. [QMapServices sharedServices].apiKey = QQMapKey;
  538. [[QMapServices sharedServices] setApiKey:QQMapKey];
  539. [[QMSSearchServices sharedServices] setApiKey:QQMapKey];
  540. // [[UIApplication sharedApplication] registerForRemoteNotifications];
  541. // // 友盟推送
  542. // //1.3.0版本开始简化初始化过程。如不需要交互式的通知,下面用下面一句话注册通知即可。
  543. // [UMessage registerForRemoteNotifications];
  544. // // for log
  545. // [UMessage setLogEnabled:NO];
  546. //BMK
  547. //直播SDK
  548. // if ([BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.tencent_live_sdk_licence]) {
  549. // [TXLiveBase setLicenceURL:TXRTMPLicence key:TXRTMPKey];
  550. // }else{
  551. // }
  552. // [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString * _Nonnull log) {
  553. // NSLog(@"wxlog:%@",log);
  554. //// [BGHUDHelper alert:log];
  555. // }];
  556. // [WXApi registerApp:WeixinAppId universalLink:@"https://aaa.com/guoxiuvideo/"];
  557. // 键盘事件
  558. [IQKeyboardManager sharedManager].enable = NO;
  559. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  560. // // jubao pay
  561. // if (WeixinAppId.length>0)
  562. // {
  563. // [BGInterface init:JBFAppId useAPI:YES withWXAppId:WeixinAppId];
  564. // }
  565. // else
  566. // {
  567. // [BGInterface init:JBFAppId useAPI:YES withWXAppId:nil];
  568. // }
  569. }
  570. #pragma mark ------ BMK
  571. - (void)showBMK
  572. {
  573. BMKMapManager *manager = [[BMKMapManager alloc]init];
  574. BOOL result = [manager start:BaiduMapKey generalDelegate:self];
  575. // [manager start:BaiduMapKey generalDelegate:nil];
  576. if (result)
  577. {
  578. }
  579. else
  580. {
  581. }
  582. }
  583. #pragma mark - ----------------------- 进入相关页面 -----------------------
  584. - (void)beginEnterMianUI
  585. {
  586. if (![NSKeyedUnarchiver unarchiveObjectWithFile:SavePath] && [IsNeedFirstIntroduce isEqualToString:@"YES"])
  587. {
  588. [self setNewFeatureVisiable];
  589. }
  590. else
  591. {
  592. if (kSupportH5Shopping == 1)
  593. {
  594. [self loadH5MianView];
  595. }
  596. else
  597. {
  598. BOOL isAutoLogin = [IMAPlatform isAutoLogin];
  599. if (isAutoLogin)
  600. {
  601. _isTabBarShouldLoginIMSDK = YES;
  602. [self enterMainUI];
  603. }
  604. else
  605. {
  606. _isTabBarShouldLoginIMSDK = NO;
  607. [self enterLoginUI];
  608. }
  609. }
  610. }
  611. }
  612. #pragma mark 进入登录页面
  613. - (void)enterLoginUI
  614. //ShowVC:(BOOL)showVC
  615. {
  616. if (self.isAlreadyPushLoginVC) {
  617. return;
  618. }
  619. self.isAlreadyPushLoginVC = YES;
  620. [BGIMLoginManager sharedInstance].isIMSDKOK = NO;
  621. if (!kSupportH5Shopping)
  622. {
  623. if ([self.window.rootViewController isKindOfClass:[BGTabBarController class]])
  624. {
  625. BGTabBarController *tmpNav = (BGTabBarController *)self.window.rootViewController;
  626. for (UIViewController *vc in tmpNav.childViewControllers)
  627. {
  628. if ([vc isKindOfClass:[BogoJHLogin class]])
  629. {
  630. return;
  631. }
  632. }
  633. }
  634. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  635. [userDefaults removeObjectForKey:kIMAPlatform_AutoLogin_Key];
  636. [userDefaults removeObjectForKey:kIMALoginParamUserKey];
  637. [userDefaults removeObjectForKey:kMyCookies];
  638. [userDefaults synchronize];
  639. NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  640. NSArray *cookieArray = [NSArray arrayWithArray:[cookieJar cookies]];
  641. for (id obj in cookieArray)
  642. {
  643. [cookieJar deleteCookie:obj];
  644. }
  645. NSString * preferredLang = [[NSUserDefaults standardUserDefaults] objectForKey:KAppLanguage];
  646. NSLog(@" 4当前语言 = %@",preferredLang);
  647. // if (showVC) {
  648. BogoJHLogin *login = [[BogoJHLogin alloc]initWithNibName:NSStringFromClass([BogoJHLogin class]) bundle:[NSBundle mainBundle]];
  649. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:login];
  650. self.window.rootViewController = nav;
  651. // }
  652. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  653. self.isAlreadyPushLoginVC = NO;
  654. });
  655. }
  656. }
  657. #pragma mark 加载h5主页
  658. - (void)loadH5MianView
  659. {
  660. if (!_webViewNav)
  661. {
  662. NSString *tmpUrl;
  663. if ([self.BuguLive.appModel.site_url length]>7)
  664. {
  665. tmpUrl = self.BuguLive.appModel.site_url;
  666. }
  667. else
  668. {
  669. tmpUrl = H5MainUrlStr;
  670. }
  671. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:tmpUrl isShowIndicator:YES];
  672. tmpController.isShowLaunchImgView = YES;
  673. _webViewNav = [[BGNavigationController alloc] initWithRootViewController:tmpController];
  674. self.window.rootViewController = _webViewNav;
  675. }
  676. else
  677. {
  678. self.window.rootViewController = _webViewNav;
  679. }
  680. }
  681. #pragma mark 加载原生主页
  682. - (void)enterMainUI
  683. {
  684. if (_isTabBarShouldLoginIMSDK)
  685. {
  686. _isTabBarShouldLoginIMSDK = NO;
  687. [[BGIMLoginManager sharedInstance] loginImSDK:NO succ:nil failed:nil];
  688. }
  689. [BGTabBarController sharedInstance].selectedIndex = 0;
  690. self.window.rootViewController = [BGTabBarController sharedInstance];
  691. [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"haveLanch"];
  692. // 换号登录发出这个通知,才会再一次调动每日首次登陆奖励,否则登录提示不会显示
  693. [[NSNotificationCenter defaultCenter]postNotificationName:@"rewardView" object:nil];
  694. }
  695. #pragma mark进入tabBar
  696. - (void)entertabBar
  697. {
  698. UITabBarController *tabBars = [BGTabBarController sharedInstance];
  699. #if kSupportH5Shopping
  700. tabBars.selectedIndex = 1;
  701. #endif
  702. self.window.rootViewController = tabBars;
  703. }
  704. - (void)validateCurrentUrl
  705. {
  706. if (self.BuguLive.doMainUrlArray)
  707. {
  708. for (NSString *tmpUrl in self.BuguLive.doMainUrlArray)
  709. {
  710. [BGUtils validateUrl:[NSURL URLWithString:tmpUrl]validateResult:^(NSURL *currentUrl, BOOL isSucc) {
  711. }];
  712. }
  713. }
  714. }
  715. #pragma mark - ----------------------- 初始化接口 -----------------------
  716. #pragma mark 异步加载初始化接口
  717. - (void)asyncInit
  718. {
  719. BOOL isAgreePrivacy = [[NSUserDefaults standardUserDefaults] boolForKey:@"isAgreePrivacy"];
  720. if (isAgreePrivacy) {
  721. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  722. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchScreen];
  723. //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  724. //2.设为3即表示:启动页将停留3s等待服务器返回广告数据,3s内等到广告数据,将正常显示广告,否则将不显示
  725. //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  726. //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  727. [XHLaunchAd setWaitDataDuration:3];
  728. [self configThird];
  729. }
  730. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  731. [parmDict setObject:@"app" forKey:@"ctl"];
  732. [parmDict setObject:@"init" forKey:@"act"];
  733. NSString *postUrl;
  734. #if kSupportH5Shopping
  735. postUrl = H5InitUrlStr;
  736. #else
  737. postUrl = self.BuguLive.currentDoMianUrlStr;
  738. #endif
  739. // isAgreePrivacy = NO;
  740. __weak AppDelegate *ws = self;
  741. [_httpsManager POSTWithUrl:postUrl paramDict:parmDict SuccessBlock:^(NSDictionary *responseJson){
  742. if (isAgreePrivacy) {
  743. if (responseJson)
  744. {
  745. [self setLaunchAboutViewWithDic:responseJson];
  746. [ws setFirstLoad:responseJson];
  747. }
  748. else
  749. {
  750. [ws loadInitError];
  751. }
  752. BogoNetworkInitModel *indexModel = [BogoNetworkInitModel mj_objectWithKeyValues:responseJson];
  753. [[BogoNetwork shareInstance] saveIndexModel:indexModel];
  754. [ws.BuguLive storageAppCurrentMainUrl:ws.BuguLive.currentDoMianUrlStr];
  755. }else{
  756. self.responseJson = responseJson;
  757. if (![self.window.rootViewController.view.subviews containsObject:self.privacyPopView]) {
  758. self.privacyPopView.url = [NSString stringWithFormat:@"%@",responseJson[@"compliance_policy"]];
  759. [self.privacyPopView show:self.window.rootViewController.view];
  760. }
  761. }
  762. } FailureBlock:^(NSError *error) {
  763. NSLog(ASLocalizedString(@"=====初始化接口失败,错误码:%ld"),error.code);
  764. // 如果非网络原因导致的错误,尝试切换域名
  765. if (error.code != NSURLErrorNetworkConnectionLost && error.code != NSURLErrorNotConnectedToInternet)
  766. {
  767. if (_currentMainUrlIndex < [ws.BuguLive.doMainUrlArray count])
  768. {
  769. NSString *tmpMainUrl = [ws.BuguLive.doMainUrlArray objectAtIndex:_currentMainUrlIndex];
  770. tmpMainUrl = [tmpMainUrl stringByAppendingString:AppDoMainUrlSuffix];
  771. ws.BuguLive.currentDoMianUrlStr = tmpMainUrl;
  772. }
  773. if (_currentMainUrlIndex >= [ws.BuguLive.doMainUrlArray count]-1)
  774. {
  775. _currentMainUrlIndex = 0;
  776. }
  777. else
  778. {
  779. _currentMainUrlIndex ++;
  780. }
  781. }
  782. [ws loadInitError];
  783. }];
  784. }
  785. //设置启动轮播图UI
  786. -(void)setLaunchAboutViewWithDic:(NSDictionary *)response{
  787. NSArray *adArr = [response valueForKey:@"start_diagram"];
  788. NSMutableArray *diagramArr = [NSMutableArray array];
  789. NSMutableArray *urlArray = [NSMutableArray array];
  790. for (int i = 0; i < adArr.count; i ++) {
  791. NSDictionary *dic = [adArr objectAtIndex:i];
  792. [diagramArr addObject:[dic valueForKey:@"image"]];
  793. [urlArray addObject:[dic valueForKey:@"url"]];
  794. }
  795. [GlobalVariables sharedInstance].guardImgArr = adArr;
  796. //配置广告数据
  797. XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration defaultConfiguration];
  798. imageAdconfiguration.contentMode = UIViewContentModeScaleAspectFill;
  799. imageAdconfiguration.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  800. //跳过按钮类型
  801. imageAdconfiguration.skipButtonType = SkipTypeTime;
  802. if(diagramArr.count == 0)
  803. {
  804. //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  805. imageAdconfiguration.imageNameOrURLString = @"lg_bg";
  806. }
  807. else
  808. {
  809. //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  810. imageAdconfiguration.imageNameOrURLString = [diagramArr componentsJoinedByString:[NSString stringWithFormat:@"%@",diagramArr.firstObject]];
  811. }
  812. // @"LaunchImage.jpg";
  813. // @"app"
  814. // response[@"data"][@"img"];
  815. //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  816. imageAdconfiguration.openModel = urlArray.firstObject;
  817. // response[@"data"][@"plug_ad_url"];
  818. imageAdconfiguration.duration = 3;
  819. // imageAdconfiguration.showFinishAnimateTime = 0.8;
  820. // [response[@"data"][@"start_figure"] integerValue];
  821. //显示开屏广告
  822. [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  823. }
  824. //点击了广告页面
  825. - (void)xhLaunchAd:(XHLaunchAd *)launchAd clickAndOpenModel:(id)openModel clickPoint:(CGPoint)clickPoint{
  826. NSString *url = (NSString *)openModel;
  827. // self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  828. // self.window.backgroundColor = kWhiteColor;
  829. // if (![self.window.rootViewController isKindOfClass:BGTabBarController.class]) {
  830. // BGTabBarController *mainViewController = [BGTabBarController sharedInstance];
  831. // CAAnimation *transition = [self animationFrom:self.window.rootViewController to:mainViewController];
  832. // BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:mainViewController];
  833. // self.window.rootViewController = nav;
  834. // [self.window makeKeyAndVisible];
  835. // }
  836. if (!url.length) {
  837. [SVProgressHUD showErrorWithStatus:NSLocalizedString(ASLocalizedString(@"链接为空"), nil)];
  838. return;
  839. }
  840. [self performSelector:@selector(pushWebVC:) withObject:url afterDelay:3];
  841. // self.mainViewController = mainViewController;
  842. }
  843. - (void)pushWebVC:(id)object{
  844. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:object isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:YES];
  845. // tmpController.navTitleStr = @"";
  846. [[AppDelegate sharedAppDelegate] presentViewController:tmpController animated:YES completion:nil];
  847. }
  848. #pragma mark 首次加载的时候相关的业务逻辑
  849. - (void)setFirstLoad:(NSDictionary *)responseDict
  850. {
  851. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  852. [self setInitData:responseDict];
  853. [self setAppConfig];
  854. if (_isFirstLoadInit)
  855. {
  856. _isFirstLoadInit = NO;
  857. [self initAdvView:responseDict];
  858. // 如果有启动广告图,则暂不加载主页
  859. NSArray *addArray = [responseDict objectForKey:@"start_diagram"];
  860. if (addArray && addArray.count >0 && [addArray isKindOfClass:[NSArray class]])
  861. {
  862. if (addArray.count)
  863. {
  864. if (![BGUtils isBlankString:_adModel.image])
  865. {
  866. MGAdvertViewController *mainViewController = [[MGAdvertViewController alloc] init];
  867. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  868. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:mainViewController];
  869. self.window.rootViewController = nav;
  870. [self.window makeKeyAndVisible];
  871. // [self beginEnterMianUI];
  872. return;
  873. }
  874. }
  875. }else{
  876. [self beginEnterMianUI];
  877. }
  878. }
  879. }
  880. - (void)xhLaunchAdShowFinish:(XHLaunchAd *)launchAd{
  881. BOOL isAutoLogin = [IMAPlatform isAutoLogin];
  882. if (isAutoLogin) {
  883. [BGTabBarController sharedInstance].selectedIndex = 0;
  884. self.window.rootViewController = [BGTabBarController sharedInstance];
  885. [[NSUserDefaults standardUserDefaults] setObject:@(YES) forKey:@"haveLanch"];
  886. }else{
  887. MGAdvertViewController *mainViewController = [[MGAdvertViewController alloc] init];
  888. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  889. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:mainViewController];
  890. self.window.rootViewController = nav;
  891. [self.window makeKeyAndVisible];
  892. }
  893. [BGTabBarController sharedInstance].adShowFinished = YES;
  894. }
  895. #pragma mark 初始化接口接在失败的情况
  896. - (void)loadInitError
  897. {
  898. [self setAppConfig];
  899. [self setAppLoginType];
  900. if (_isFirstLoadInit)
  901. {
  902. _isFirstLoadInit = NO;
  903. [self beginEnterMianUI];
  904. }
  905. [self performSelector:@selector(asyncInit) withObject:nil afterDelay:5];
  906. }
  907. #pragma mark 接收初始化接口的参数
  908. - (void)setInitData:(NSDictionary *)responseDict
  909. {
  910. self.BuguLive.appModel = [AppModel mj_objectWithKeyValues:responseDict];
  911. self.BuguLive.appModel.isInitSucceed = YES;
  912. if (![BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.tencent_live_sdk_key]) {
  913. [TXLiveBase setLicenceURL:[GlobalVariables sharedInstance].appModel.tencent_live_sdk_licence key:[GlobalVariables sharedInstance].appModel.tencent_live_sdk_key];
  914. }
  915. if (![BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.tencent_video_sdk_key]) {
  916. [TXUGCBase setLicenceURL:[GlobalVariables sharedInstance].appModel.tencent_video_sdk_licence key:[GlobalVariables sharedInstance].appModel.tencent_video_sdk_key];
  917. }
  918. // [TXUGCBase setLicenceURL:@"http://license.vod2.myqcloud.com/license/v1/c81c650cf0669fef99ef446feafe3107/TXUgcSDK.licence" key:@"90ce296d9754df2ddfdc7169eed312d9"];
  919. NSArray *domainArray = [responseDict objectForKey:@"domain_list"];
  920. if (domainArray && [domainArray isKindOfClass:[NSArray class]])
  921. {
  922. [self.BuguLive storageAppMainUrls:domainArray];
  923. }
  924. if (self.BuguLive.listMsgMArray)
  925. {
  926. [self.BuguLive.listMsgMArray removeAllObjects];
  927. }
  928. NSArray *listmsg = [responseDict objectForKey:@"listmsg"];
  929. if (listmsg && [listmsg isKindOfClass:[NSArray class]])
  930. {
  931. for (NSDictionary *tmpDic in listmsg)
  932. {
  933. CustomMessageModel *customMessageModel = [CustomMessageModel mj_objectWithKeyValues:tmpDic];
  934. [customMessageModel prepareForRender];
  935. [self.BuguLive.listMsgMArray addObject:customMessageModel];
  936. }
  937. }
  938. if (self.BuguLive.appModel.version.has_upgrade == 1)
  939. {
  940. self.BuguLive.ios_down_url = self.BuguLive.appModel.version.ios_down_url;
  941. //强制升级:forced_upgrade ; 0:非强制升级,可取消; 1:强制升级
  942. if (self.BuguLive.appModel.version.forced_upgrade == 1)
  943. {
  944. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  945. }
  946. else
  947. {
  948. FWWeakify(self)
  949. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"发现新版本,需要升级吗?")destructiveAction:^{
  950. FWStrongify(self)
  951. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.BuguLive.ios_down_url]];
  952. } cancelAction:^{
  953. }];
  954. }
  955. }
  956. }
  957. #pragma mark 配置app内的相关称呼
  958. - (void)setAppConfig
  959. {
  960. if (!self.BuguLive.appModel.short_name || [self.BuguLive.appModel.short_name isEqualToString:@""])
  961. {
  962. self.BuguLive.appModel.short_name = ShortNameStr;
  963. }
  964. if (!self.BuguLive.appModel.ticket_name || [self.BuguLive.appModel.ticket_name isEqualToString:@""])
  965. {
  966. self.BuguLive.appModel.ticket_name = TicketNameStr;
  967. }
  968. if (!self.BuguLive.appModel.account_name || [self.BuguLive.appModel.account_name isEqualToString:@""])
  969. {
  970. self.BuguLive.appModel.account_name = AccountNameStr;
  971. }
  972. if (!self.BuguLive.appModel.diamond_name || [self.BuguLive.appModel.diamond_name isEqualToString:@""])
  973. {
  974. self.BuguLive.appModel.diamond_name = DiamondNameStr;
  975. }
  976. }
  977. #pragma mark 如果异步初始化接口失败,则显示所有的登录方式
  978. - (void)setAppLoginType
  979. {
  980. if (![BGUtils isBlankString:WeixinAppId])
  981. {
  982. self.BuguLive.appModel.has_wx_login = 1;
  983. }
  984. if (![BGUtils isBlankString:QQAppId])
  985. {
  986. self.BuguLive.appModel.has_qq_login = 1;
  987. }
  988. if (![BGUtils isBlankString:SinaAppId])
  989. {
  990. self.BuguLive.appModel.has_sina_login = 1;
  991. }
  992. self.BuguLive.appModel.has_mobile_login = 1;
  993. }
  994. #pragma mark - ----------------------- 启动广告图 -----------------------
  995. #pragma mark 初始化广告图
  996. - (void)initAdvView:(NSDictionary *)responseDict
  997. {
  998. if (![NSKeyedUnarchiver unarchiveObjectWithFile:SavePath] && [IsNeedFirstIntroduce isEqualToString:@"YES"])
  999. {
  1000. return;
  1001. }
  1002. // 启动广告图
  1003. NSArray *addArray = [responseDict objectForKey:@"start_diagram"];
  1004. if (addArray && [addArray isKindOfClass:[NSArray class]])
  1005. {
  1006. if (addArray.count)
  1007. {
  1008. _adModel = [HMHotBannerModel mj_objectWithKeyValues:[addArray firstObject]];
  1009. _advImgView = [[FLAnimatedImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1010. _advImgView.userInteractionEnabled = YES;
  1011. UITapGestureRecognizer *singleRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(jumpToAdView)];
  1012. [_advImgView addGestureRecognizer:singleRecognizer];
  1013. [self performSelector:@selector(changeShowAdImgView) withObject:nil afterDelay:kAdImgViewLoadFromNetTimes];
  1014. if ([BGUtils isBlankString:_adModel.image])
  1015. {
  1016. return;
  1017. }
  1018. FWWeakify(self)
  1019. [_advImgView sd_setImageWithURL:[NSURL URLWithString:_adModel.image] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  1020. FWStrongify(self)
  1021. if (self.isShowAdImgView)
  1022. {
  1023. [self beginEnterMianUI];
  1024. [self.window addSubview:_advImgView];
  1025. [self performSelector:@selector(removeAdvImage) withObject:nil afterDelay:3];
  1026. self.isShowAdImgView = NO;
  1027. }
  1028. }];
  1029. }
  1030. }
  1031. }
  1032. - (void)changeShowAdImgView
  1033. {
  1034. if (self.isShowAdImgView)
  1035. {
  1036. // [self beginEnterMianUI];
  1037. }
  1038. _isShowAdImgView = NO;
  1039. }
  1040. #pragma mark 退出广告图
  1041. - (void)removeAdvImage
  1042. {
  1043. [UIView animateWithDuration:0.3f animations:^{
  1044. _advImgView.transform = CGAffineTransformMakeScale(0.5f, 0.5f);
  1045. _advImgView.alpha = 0.f;
  1046. } completion:^(BOOL finished) {
  1047. [_advImgView removeFromSuperview];
  1048. }];
  1049. }
  1050. #pragma mark 启动广告图的点击跳转
  1051. - (void)jumpToAdView
  1052. {
  1053. if (_adModel.url && !_isAdTouched)
  1054. {
  1055. if (kSupportH5Shopping)
  1056. {
  1057. [self loadH5MianView];
  1058. }
  1059. else
  1060. {
  1061. if ([AdJumpViewModel adToOthersWith:_adModel])
  1062. {
  1063. [[NSNotificationCenter defaultCenter] postNotificationName:@"adjump" object:[AdJumpViewModel adToOthersWith:_adModel]];
  1064. }
  1065. }
  1066. }
  1067. _isAdTouched = YES;
  1068. }
  1069. #pragma mark - ----------------------- 首次安装简介 -----------------------
  1070. #pragma mark 首次安装显示的多张简介图
  1071. - (void)setNewFeatureVisiable
  1072. {
  1073. [NSKeyedArchiver archiveRootObject:@"NOFirst_login" toFile:SavePath];
  1074. NewFeatureController *controller = [[NewFeatureController alloc]init];
  1075. controller.delegate=self;
  1076. controller.Datasourse=self;
  1077. __weak AppDelegate *weakSelf = self;
  1078. [controller setStartAppBlock:^{
  1079. BOOL isAutoLogin = [IMAPlatform isAutoLogin];
  1080. if (isAutoLogin)
  1081. {
  1082. _isTabBarShouldLoginIMSDK = YES;
  1083. [weakSelf enterMainUI];
  1084. }
  1085. else
  1086. {
  1087. _isTabBarShouldLoginIMSDK = NO;
  1088. [weakSelf enterLoginUI];
  1089. }
  1090. }];
  1091. self.window.rootViewController=controller;
  1092. }
  1093. #pragma mark NewFeatureControllerDatasourse (数据源代理,告诉控制器显示几张图片,和显示什么图片)
  1094. - (NSInteger)NewFeatureControllerPhotosNumber
  1095. {
  1096. NSString *countStr = FirstIntroduceImgCount;
  1097. return [countStr integerValue];
  1098. }
  1099. -(UIImageView*)NewFeatureControllerImageViewIndex:(NSUInteger)index
  1100. {
  1101. NSString *imageName = [NSString stringWithFormat:@"new_feature_%ld.jpg",(unsigned long)index];
  1102. return [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
  1103. }
  1104. - (void)applicationWillTerminate:(UIApplication *)application
  1105. {
  1106. [[SDImageCache sharedImageCache] clearMemory];
  1107. }
  1108. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
  1109. {
  1110. [[SDImageCache sharedImageCache] clearMemory];
  1111. }
  1112. #pragma mark - ----------------------- 监听网络 -----------------------
  1113. - (void)startMonitor
  1114. {
  1115. [[AFNetworkReachabilityManager sharedManager] startMonitoring]; //开始监听网络状态变化
  1116. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(ReachabilityDidChange:) name:AFNetworkingReachabilityDidChangeNotification object:nil];
  1117. }
  1118. - (void)ReachabilityDidChange:(NSNotification *)not
  1119. {
  1120. BOOL netConnected;
  1121. [self.noNetworkView removeFromSuperview];
  1122. self.noNetworkView = nil;
  1123. self.noNetworkView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  1124. [self.window addSubview:self.noNetworkView];
  1125. NSDictionary *userInfo = not.userInfo;
  1126. _reachabilityStatus = [userInfo[AFNetworkingReachabilityNotificationStatusItem] integerValue];
  1127. NSLog(@"============:ReachabilityDidChange");
  1128. switch (_reachabilityStatus) {
  1129. case AFNetworkReachabilityStatusUnknown:
  1130. netConnected = _isFirstLoadInit;
  1131. break;
  1132. case AFNetworkReachabilityStatusNotReachable:
  1133. netConnected = _isFirstLoadInit;
  1134. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"哎呀!网络不大给力!")];
  1135. break;
  1136. case AFNetworkReachabilityStatusReachableViaWWAN:
  1137. netConnected = YES;
  1138. NSLog(ASLocalizedString(@"您正在使用手机自带网络进行访问"));
  1139. break;
  1140. case AFNetworkReachabilityStatusReachableViaWiFi:
  1141. netConnected = YES;
  1142. NSLog(ASLocalizedString(@"您正在使用wifi进行访问"));
  1143. break;
  1144. default:
  1145. break;
  1146. }
  1147. self.noNetworkView.hidden = netConnected;
  1148. if (_netChangedTimes >= 1 && netConnected && !self.BuguLive.appModel.isInitSucceed)
  1149. {
  1150. [self showBMK];
  1151. [self loadInitError];
  1152. [_mapLocationView startLocate];
  1153. }
  1154. _netChangedTimes ++;
  1155. }
  1156. #pragma mark - ----------------------- 应用回调 -----------------------
  1157. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  1158. if([MobClickLink handleUniversalLink:userActivity delegate:self])
  1159. {
  1160. return YES;
  1161. }
  1162. return YES;
  1163. }
  1164. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  1165. {
  1166. // [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url];
  1167. if ([MobClickLink handleLinkURL:url delegate:self]) {
  1168. return YES;
  1169. }
  1170. return [self handleAllUrl:application url:url];
  1171. }
  1172. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  1173. {
  1174. return [self handleAllUrl:application url:url];
  1175. }
  1176. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
  1177. {
  1178. if ([MobClickLink handleLinkURL:url delegate:self]) {
  1179. return YES;
  1180. }
  1181. [[GIDSignIn sharedInstance] handleURL:url];
  1182. #pragma mark - 暂时注释
  1183. // [[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options];
  1184. return [self handleAllUrl:app url:url];
  1185. }
  1186. - (BOOL)handleAllUrl:(UIApplication*)app url:(NSURL*)url
  1187. {
  1188. BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url];
  1189. [GIDSignIn.sharedInstance handleURL:url];
  1190. if ([url.host isEqualToString:@"safepay"])
  1191. {
  1192. // //跳转支付宝钱包进行支付,处理支付结果
  1193. // [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  1194. // NSLog(@"result = %@",resultDic);
  1195. // }];
  1196. return YES;
  1197. }
  1198. // else if([url.absoluteString rangeOfString:WeixinAppId].location != NSNotFound)
  1199. // {
  1200. // // 微信支付
  1201. // return [WXApi handleOpenURL:url delegate:self];
  1202. // }
  1203. return result;
  1204. }
  1205. #pragma mark - MobClickLinkDelegate
  1206. - (void)getLinkPath:(NSString *)path params:(NSDictionary *)params{
  1207. [GlobalVariables sharedInstance].openinstallDic = params;
  1208. }
  1209. //微信支付回调处理
  1210. //- (void)onResp:(BaseResp*)resp
  1211. //{
  1212. // NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode];
  1213. // NSString *strTitle;
  1214. //
  1215. // if([resp isKindOfClass:[SendMessageToWXResp class]])
  1216. // {
  1217. // strTitle = [NSString stringWithFormat:ASLocalizedString(@"发送媒体消息结果")];
  1218. // }
  1219. // if([resp isKindOfClass:[PayResp class]])
  1220. // {
  1221. // // 支付返回结果,实际支付结果需要去微信服务器端查询
  1222. // if([SResBase shareClient].mg_pay_block)
  1223. // {
  1224. // // 充值界面的支付回掉处理
  1225. // SResBase* retobj = SResBase.new;
  1226. // if( resp.errCode == -1 )
  1227. // {
  1228. // retobj.msuccess = NO;
  1229. // retobj.mmsg = ASLocalizedString(@"支付出现异常");
  1230. // }
  1231. // else if( resp.errCode == -2 )
  1232. // {
  1233. // retobj.msuccess = NO;
  1234. // retobj.mmsg = ASLocalizedString(@"用户取消了支付");
  1235. // }
  1236. // else
  1237. // {
  1238. // retobj.msuccess = YES;
  1239. // retobj.mmsg = ASLocalizedString(@"支付成功");
  1240. // }
  1241. //
  1242. // [SResBase shareClient].mg_pay_block( retobj );
  1243. // return;
  1244. // }
  1245. //
  1246. // strTitle = [NSString stringWithFormat:ASLocalizedString(@"支付结果")];
  1247. //
  1248. // switch (resp.errCode)
  1249. // {
  1250. // // retcode 0:支付成功 -1:支付失败 -2:用户取消
  1251. // case WXSuccess:
  1252. // strMsg = ASLocalizedString(@"支付成功!");
  1253. // NSLog(ASLocalizedString(@"支付成功-PaySuccess,retcode = %d"), resp.errCode);
  1254. // [[NSNotificationCenter defaultCenter]postNotificationName:@"PaySuccess" object:nil];
  1255. //
  1256. // break;
  1257. // default:
  1258. // if (resp.errCode == -2)
  1259. // {
  1260. // strMsg = ASLocalizedString(@"用户取消");
  1261. // }
  1262. // else if(resp.errCode == -1)
  1263. // {
  1264. // strMsg = ASLocalizedString(@"支付失败");
  1265. // }
  1266. // NSLog(ASLocalizedString(@"支付结果:错误,retcode = %d, retstr = %@"), resp.errCode,resp.errStr);
  1267. // break;
  1268. // }
  1269. // [FanweMessage alert:strMsg];
  1270. // }
  1271. // else if([resp isKindOfClass:[SendAuthResp class]])
  1272. // {
  1273. // SendAuthResp *myresp = (SendAuthResp *)resp;
  1274. //
  1275. // NSString *jsonStr = [NSString stringWithFormat:@"{\"login_sdk_type\":\"wxlogin\",\"code\":\"%@\",\"err_code\":\"%d\"}",myresp.code,resp.errCode];
  1276. // [[NSNotificationCenter defaultCenter]postNotificationName:kWXLoginBack object:jsonStr];
  1277. //
  1278. // switch (resp.errCode)
  1279. // {
  1280. // // retcode: 0:用户同意 -4:用户拒绝授权 -2:用户取消
  1281. // case -4:
  1282. // strMsg = ASLocalizedString(@"用户拒绝授权!");
  1283. // NSLog(ASLocalizedString(@"支付成功-PaySuccess,retcode = %d"), resp.errCode);
  1284. // break;
  1285. // case -2:
  1286. // strMsg = ASLocalizedString(@"用户取消!");
  1287. // NSLog(ASLocalizedString(@"支付成功-PaySuccess,retcode = %d"), resp.errCode);
  1288. // break;
  1289. //
  1290. // default:
  1291. //
  1292. // break;
  1293. // }
  1294. // }
  1295. //}
  1296. #pragma mark - ----------------------- 推送相关 -----------------------
  1297. - (void)initUMPushOptions:(NSDictionary *)launchOptions {
  1298. // {
  1299. // // iOS 10之前
  1300. // UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
  1301. // [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  1302. //
  1303. // // iOS 10
  1304. // UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  1305. // [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error)
  1306. // {
  1307. // if (!error)
  1308. // {
  1309. // NSLog(@"request authorization succeeded!");
  1310. // }
  1311. // }];
  1312. //
  1313. // [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  1314. // NSLog(@"%@",settings);
  1315. // }];
  1316. // }
  1317. PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
  1318. pushRegistry.delegate = self;
  1319. pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
  1320. // Push组件基本功能配置
  1321. // UMessageRegisterEntity* entity =[[UMessageRegisterEntity alloc] init];
  1322. //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
  1323. // entity.types =UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionSound|UMessageAuthorizationOptionAlert;
  1324. [UNUserNotificationCenter currentNotificationCenter].delegate=self;
  1325. [UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:nil completionHandler:^(BOOL granted,NSError*_Nullable error){
  1326. if(granted){
  1327. }else{
  1328. }
  1329. }];
  1330. }
  1331. //iOS 10 前台收到通知(远程推送和本地通知)
  1332. -(void)userNotificationCenter:(UNUserNotificationCenter*)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler{
  1333. NSDictionary* userInfo = notification.request.content.userInfo;
  1334. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]){
  1335. [UMessage setAutoAlert:NO];
  1336. //必须加这句代码
  1337. [UMessage didReceiveRemoteNotification:userInfo];
  1338. }else{
  1339. //应用处于前台时的本地推送接受
  1340. if ([userInfo[@"callType"] intValue] == MSG_PRIVATE_CallAudio ||
  1341. [userInfo[@"callType"] intValue] == MSG_PRIVATE_CallVideo) {
  1342. [self judjeLaunchSuccess:userInfo];
  1343. }
  1344. }
  1345. completionHandler(UNNotificationPresentationOptionSound|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionAlert);
  1346. }
  1347. // iOS 10 Support 程序运行于后台 或杀死 点击推送通知 都会走这个方法
  1348. -(void)userNotificationCenter:(UNUserNotificationCenter*)center didReceiveNotificationResponse:(UNNotificationResponse*)response withCompletionHandler:(void(^)(void))completionHandler{
  1349. NSDictionary* userInfo = response.notification.request.content.userInfo;
  1350. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]){
  1351. NSLog(@"%s",__func__);
  1352. NSLog(@"%@",userInfo);
  1353. if([[userInfo allKeys] containsObject:@"com.google.firebase.auth"])
  1354. {
  1355. return;
  1356. }
  1357. if ([userInfo toInt:@"type"] == 0)//检查直播状态
  1358. {
  1359. [self checkVideoStatus:userInfo andTag:0];
  1360. }
  1361. else if ([userInfo toInt:@"type"] == 5)//友盟推送到付款界面
  1362. {
  1363. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_user_pai isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  1364. tmpController.navTitleStr = ASLocalizedString(@"我的竞拍");
  1365. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1366. }
  1367. else if ([userInfo toInt:@"type"] == 4)//会员中心
  1368. {
  1369. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:[userInfo toString:@"url"] isShowIndicator:YES];
  1370. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1371. }
  1372. else
  1373. {
  1374. if (_isEnterForeground)
  1375. {
  1376. [self playCustomSound];//播放自定义推送声音
  1377. }
  1378. }
  1379. //必须加这句代码
  1380. [UMessage didReceiveRemoteNotification:userInfo];
  1381. }else{
  1382. //应用处于后台时的本地推送接受
  1383. // 判断为本地通知
  1384. if ([userInfo[@"callType"] intValue] == MSG_PRIVATE_CallAudio ||
  1385. [userInfo[@"callType"] intValue] == MSG_PRIVATE_CallVideo) {
  1386. [self judjeLaunchSuccess:userInfo];
  1387. }
  1388. }
  1389. completionHandler(); // 系统要求执行这个方法
  1390. }
  1391. - (void)judjeLaunchSuccess:(NSDictionary*)userInfo {
  1392. if (self.isLaunchSuccess) {
  1393. [AudioChatTool.shareInstance pushAudioChatWithDict:userInfo];
  1394. return;
  1395. }
  1396. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1397. [self judjeLaunchSuccess:userInfo];
  1398. });
  1399. }
  1400. #pragma mark - 友盟普通推送设置
  1401. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  1402. {
  1403. // NSLog(@"deviceToken=%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
  1404. // stringByReplacingOccurrencesOfString: @">" withString: @""]
  1405. // stringByReplacingOccurrencesOfString: @" " withString: @""]);
  1406. // self.BuguLive.deviceToken = [[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
  1407. // stringByReplacingOccurrencesOfString: @">" withString: @""]
  1408. // stringByReplacingOccurrencesOfString: @" " withString: @""];
  1409. // if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {
  1410. // if (![deviceToken isKindOfClass:[NSData class]]) {
  1411. // //记录获取token失败的描述
  1412. // return;
  1413. // }
  1414. // const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];
  1415. // NSString *strToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
  1416. // ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
  1417. // ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
  1418. // ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
  1419. // NSLog(@"deviceToken1:%@", strToken);
  1420. // self.BuguLive.deviceToken = strToken;
  1421. // } else {
  1422. // NSString *token = [NSString
  1423. // stringWithFormat:@"%@",deviceToken];
  1424. // token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];
  1425. // token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
  1426. // token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  1427. // self.BuguLive.deviceToken = token;
  1428. // NSLog(@"deviceToken2 is: %@", token);
  1429. // }
  1430. if(![deviceToken isKindOfClass:[NSData class]]) {
  1431. return;
  1432. }
  1433. const unsigned * tokenBytes =(const unsigned*)[deviceToken bytes];
  1434. NSString*hexToken =[NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
  1435. ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
  1436. ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
  1437. ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
  1438. NSLog(@"deviceToken:%@",hexToken);
  1439. self.BuguLive.deviceToken = hexToken;
  1440. // self.BuguLive.new_deviceToken = deviceToken;
  1441. // [[IMAPlatform sharedInstance] configOnAppRegistAPNSWithDeviceToken:deviceToken];
  1442. //1.2.7版本开始不需要用户再手动注册devicetoken,SDK会自动注册
  1443. //传入的devicetoken是系统回调didRegisterForRemoteNotificationsWithDeviceToken的入参,切记
  1444. [UMessage registerDeviceToken:deviceToken];
  1445. [[NSNotificationCenter defaultCenter]postNotificationName:@"getDeviceTokenComplete" object:nil];
  1446. [self performSelector:@selector(configApns) withObject:nil afterDelay:5];
  1447. }
  1448. #pragma mark 上传设备id(友盟推送)
  1449. - (void)configApns
  1450. {
  1451. [AppViewModel updateApnsCode];
  1452. }
  1453. #pragma mark 播放自定义推送声音
  1454. - (void)playCustomSound
  1455. {
  1456. //声音文件格式转换代码
  1457. //afconvert /System/Library/Sounds/Submarine.aiff ~/Desktop/sub.caf -d ima4 -f caff -v
  1458. NSString *path = [[NSBundle mainBundle] pathForResource:@"mycustomsound2" ofType:@"aiff"];
  1459. if (path) {
  1460. //注册声音到系统
  1461. AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&shake_sound_male_id);
  1462. AudioServicesPlaySystemSound(shake_sound_male_id);
  1463. }
  1464. AudioServicesPlaySystemSound(shake_sound_male_id); //播放注册的声音,(此句代码,可以在本类中的任意位置调用,不限于本方法中)
  1465. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); //让手机震动
  1466. }
  1467. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  1468. {
  1469. NSLog(@"%s",__func__);
  1470. NSLog(@"%@",userInfo);
  1471. [UMessage didReceiveRemoteNotification:userInfo];
  1472. }
  1473. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  1474. {
  1475. NSLog(@"%s",__func__);
  1476. NSString *error_str = [NSString stringWithFormat: @"%@", error];
  1477. NSLog(@"Failed to get token, error:%@", error_str);
  1478. }
  1479. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  1480. {
  1481. NSLog(@"%s",__func__);
  1482. NSLog(@"%@",userInfo);
  1483. if([[userInfo allKeys] containsObject:@"com.google.firebase.auth"])
  1484. {
  1485. return;
  1486. }
  1487. if ([userInfo toInt:@"type"] == 0)//检查直播状态
  1488. {
  1489. [self checkVideoStatus:userInfo andTag:0];
  1490. }
  1491. else if ([userInfo toInt:@"type"] == 5)//友盟推送到付款界面
  1492. {
  1493. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:self.BuguLive.appModel.h5_url.url_user_pai isShowIndicator:YES isShowNavBar:YES isShowBackBtn:YES];
  1494. tmpController.navTitleStr = ASLocalizedString(@"我的竞拍");
  1495. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1496. }
  1497. else if ([userInfo toInt:@"type"] == 4)//会员中心
  1498. {
  1499. BGMainWebViewController *tmpController = [BGMainWebViewController webControlerWithUrlStr:[userInfo toString:@"url"] isShowIndicator:YES];
  1500. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1501. }
  1502. else
  1503. {
  1504. if (_isEnterForeground)
  1505. {
  1506. [self playCustomSound];//播放自定义推送声音
  1507. }
  1508. }
  1509. }
  1510. #pragma mark - ********************** VOIP pushkitDelegate **********************
  1511. - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{
  1512. if([credentials.token length] == 0) {
  1513. NSLog(@"voip token NULL");
  1514. return;
  1515. }
  1516. if(![credentials.token isKindOfClass:[NSData class]]) {
  1517. return;
  1518. }
  1519. const unsigned * tokenBytes =(const unsigned*)[credentials.token bytes];
  1520. NSString*hexToken =[NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",
  1521. ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
  1522. ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
  1523. ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
  1524. NSLog(@"VOIP deviceToken:%@",hexToken);
  1525. //应用启动获取token,并上传服务器 ⚠️⚠️⚠️这个token和平常的推送token不一样,需要区分开来⚠️⚠️⚠️
  1526. self.BuguLive.voip_deviceToken = hexToken;
  1527. self.BuguLive.new_deviceToken = credentials.token;
  1528. //8762d88591aede5d5e1d3534203e0fdd0ab6aa038aa6619332c26cb8ada5dfea 8P
  1529. //79b028801ddc510eafa1b9fbefc4881cf81f4c1dcd41dddc5e5d4f687f09d135
  1530. // NSString * token = [[[[credentials.token description] stringByReplacingOccurrencesOfString:@"<"withString:@""]
  1531. // stringByReplacingOccurrencesOfString:@">" withString:@""]
  1532. // stringByReplacingOccurrencesOfString:@" " withString:@""];
  1533. // NSLog(@"VOIP token = %@",token);
  1534. //token上传服务器
  1535. // [self performSelector:@selector(configApnsVoip) withObject:nil afterDelay:5];
  1536. }
  1537. #pragma mark 上传设备id(Voip推送)
  1538. - (void)configApnsVoip {
  1539. [AppViewModel updateApnsVoipCode];
  1540. }
  1541. //收到推送,未运行,您的应用程序将自动启动,您有30s的时间处理这个事件
  1542. - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
  1543. [[NSNotificationCenter defaultCenter] postNotificationName:@"PKPushIncomingCallReportedNotification" object:nil];
  1544. if (![type isEqualToString:@"PKPushTypeVoIP"]) {
  1545. return;
  1546. }
  1547. NSLog(@"voip dic %@",payload.dictionaryPayload);
  1548. [AudioChatTool.shareInstance receivePushVoipMsgWithNotification:payload.dictionaryPayload];
  1549. }
  1550. #pragma mark - ----------------------- 其他 -----------------------
  1551. //已经进入前台
  1552. -(void)applicationDidBecomeActive:(UIApplication *)application{
  1553. AVAudioSession *session=[AVAudioSession sharedInstance];
  1554. [session setCategory:AVAudioSessionCategoryPlayback error:nil];
  1555. }
  1556. //即将进入前台
  1557. - (void)applicationWillEnterForeground:(UIApplication *)application
  1558. {
  1559. NSLog(@"%s",__func__);
  1560. AVAudioSession *session=[AVAudioSession sharedInstance];
  1561. [session setCategory:AVAudioSessionCategoryPlayback error:nil];
  1562. if ([BGIMLoginManager sharedInstance].isIMSDKOK)
  1563. {
  1564. [AppViewModel userStateChange:@"Login"];
  1565. [[NSNotificationCenter defaultCenter] postNotificationName:kRefreshHome object:nil userInfo:nil];
  1566. [self getInformation];
  1567. }
  1568. if (!_isFirstLoad && [IMAPlatform sharedInstance].host.imUserId)
  1569. {
  1570. if ([[IMAPlatform sharedInstance].host.imUserId intValue])
  1571. {
  1572. [[IMAPlatform sharedInstance].host getMyInfo:nil];
  1573. }
  1574. }
  1575. NSDate *nowDate = [NSDate date];
  1576. self.BuguLive.foreGroundTime = [nowDate timeIntervalSince1970];
  1577. #if kSupportH5Shopping
  1578. // if (!_isFirstLoad) {
  1579. //
  1580. // NSTimeInterval nowInterval = [nowDate timeIntervalSince1970];
  1581. //
  1582. // if (nowInterval - _willResignActiveDate > self.BuguLive.appModel.reload_time)
  1583. // {
  1584. // [self loadH5MianView];
  1585. // }
  1586. // }
  1587. #endif
  1588. _isFirstLoad = NO;
  1589. _isEnterForeground = YES;
  1590. // 必须
  1591. // FW code start
  1592. // [BGInterface applicationWillEnterForeground:application];
  1593. // FW code end
  1594. }
  1595. #pragma mark 已经进入后台
  1596. - (void)applicationDidEnterBackground:(UIApplication *)application
  1597. {
  1598. NSLog(@"%s",__func__);
  1599. // [AppViewModel userStateChange:@"Logout"];
  1600. NSDate *nowDate = [NSDate date];
  1601. self.BuguLive.backGroundTime = [nowDate timeIntervalSince1970];
  1602. #if kSupportH5Shopping
  1603. if (self.BuguLive.appModel.reload_time>0)
  1604. {
  1605. _willResignActiveDate = [nowDate timeIntervalSince1970];
  1606. }
  1607. #endif
  1608. _isEnterForeground = NO;
  1609. }
  1610. - (void)applicationWillResignActive:(UIApplication *)application {
  1611. //
  1612. // [self pauseVideo];
  1613. }
  1614. -(void)pauseVideo{
  1615. //开启后台处理多媒体事件
  1616. [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
  1617. AVAudioSession *session=[AVAudioSession sharedInstance];
  1618. [session setActive:YES error:nil];
  1619. //后台播放
  1620. [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
  1621. UIApplication* app = [UIApplication sharedApplication];
  1622. __block UIBackgroundTaskIdentifier bgTask;
  1623. bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
  1624. dispatch_async(dispatch_get_main_queue(), ^{
  1625. if (bgTask != UIBackgroundTaskInvalid)
  1626. {
  1627. bgTask = UIBackgroundTaskInvalid;
  1628. }
  1629. });
  1630. }];
  1631. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  1632. dispatch_async(dispatch_get_main_queue(), ^{
  1633. if (bgTask != UIBackgroundTaskInvalid)
  1634. {
  1635. bgTask = UIBackgroundTaskInvalid;
  1636. }
  1637. });
  1638. });
  1639. }
  1640. #pragma mark 获取粘贴板的信息
  1641. - (void)getInformation
  1642. {
  1643. self.BuguLive = [GlobalVariables sharedInstance];
  1644. UIPasteboard *pboard = [UIPasteboard generalPasteboard];
  1645. _pboardString = pboard.string;
  1646. NSString *keyString =[GTMBase64 decodeBase64:@"8J+UkQ=="];
  1647. if ([_pboardString rangeOfString:keyString].location != NSNotFound)
  1648. {
  1649. self.BuguLive.privateKeyString = (NSString *) [[[[_pboardString componentsSeparatedByString:keyString] objectAtIndex:1] componentsSeparatedByString:keyString] objectAtIndex:0];
  1650. if (self.BuguLive.privateKeyString)
  1651. {
  1652. if ([self.BuguLive.privateKeyString length])
  1653. {
  1654. NSDictionary *dict = [NSDictionary dictionary];
  1655. [self checkVideoStatus:dict andTag:1];
  1656. }
  1657. }
  1658. }
  1659. }
  1660. #pragma mark 检查直播状态 tag: 0:推送 1:私密直播
  1661. // 私密直播的提示:首先如果直播结束跳转到个人中心,否则判断是否在直播间,不在直播间就进入直播间否则做已在直播间的提示
  1662. - (void)checkVideoStatus:(NSDictionary *)dict andTag:(NSInteger)tag
  1663. {
  1664. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  1665. [mDict setObject:@"video" forKey:@"ctl"];
  1666. [mDict setObject:@"check_status" forKey:@"act"];
  1667. NSString *room_id = [dict toString:@"room_id"];
  1668. if (tag == 0 && room_id && ![room_id isEqualToString:@""])
  1669. {
  1670. [mDict setObject:[dict toString:@"room_id"] forKey:@"room_id"];
  1671. }
  1672. if (tag == 1 && self.BuguLive.privateKeyString.length > 0)
  1673. {
  1674. [mDict setObject:self.BuguLive.privateKeyString forKey:@"private_key"];
  1675. }
  1676. FWWeakify(self)
  1677. [_httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  1678. FWStrongify(self)
  1679. if ([responseJson toInt:@"live_in"] == FW_LIVE_STATE_ING) //正在直播
  1680. {
  1681. self.pushUserModel = [UserModel mj_objectWithKeyValues:responseJson];
  1682. if (![IMAPlatform isHost:self.pushUserModel.user_id])
  1683. {
  1684. if ([self.BuguLive.liveState.roomId intValue] && tag == 1) // 当前正在直播间
  1685. {
  1686. // 表示当前用户正在直播间(可能是直播或者看直播)
  1687. if (self.BuguLive.liveState.isLiveHost == YES) // 主播
  1688. {
  1689. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您当前正在直播")];
  1690. self.BuguLive.privateKeyString = @"";
  1691. return ;
  1692. }
  1693. else//不是主播
  1694. {
  1695. if ([self.BuguLive.liveState.roomId isEqualToString:self.pushUserModel.room_id])//正在直播间
  1696. {
  1697. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您当前正在直播间内")];
  1698. self.BuguLive.privateKeyString = @"";
  1699. return;
  1700. }
  1701. else
  1702. {
  1703. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"您当前正在直播间内")];
  1704. return;
  1705. }
  1706. }
  1707. }
  1708. else // 当前不在直播间内,接收到推送或者私密直播
  1709. {
  1710. if (tag == 0)
  1711. { // 推送
  1712. [self showAlert:responseJson tag:2];
  1713. }
  1714. else
  1715. { // 私密直播
  1716. [self showAlert:responseJson tag:3];
  1717. }
  1718. }
  1719. }
  1720. }
  1721. else if ([responseJson toInt:@"live_in"] == FW_LIVE_STATE_OVER)
  1722. {
  1723. [UIPasteboard generalPasteboard].string = @"";
  1724. [self showAlert:responseJson tag:8];
  1725. self.homePageUserId = [responseJson toString:@"user_id"];
  1726. self.BuguLive.privateKeyString = @"";
  1727. }
  1728. } FailureBlock:^(NSError *error) {
  1729. }];
  1730. }
  1731. - (void)showAlert:(NSDictionary *)responseJson tag:(int)tag
  1732. {
  1733. FWWeakify(self)
  1734. [FanweMessage alert:nil message:[responseJson toString:@"content"] destructiveAction:^{
  1735. FWStrongify(self)
  1736. if (tag == 2)
  1737. { //用户正在前台时收到推送
  1738. [self enterNowLive];
  1739. }
  1740. else if (tag == 3)
  1741. { //私密直播
  1742. [self enterNowLive];
  1743. }
  1744. else if (tag == 8)
  1745. {
  1746. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  1747. tmpController.user_id = self.homePageUserId;
  1748. tmpController.type = 0;
  1749. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  1750. }
  1751. } cancelAction:^{
  1752. }];
  1753. }
  1754. - (void)enterNowLive
  1755. {
  1756. UserModel *model = _pushUserModel;
  1757. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  1758. item.chatRoomId = model.group_id;
  1759. item.avRoomId = [model.room_id intValue];
  1760. item.title = model.room_id;
  1761. item.vagueImgUrl = model.head_image;
  1762. TCShowUser *showUser = [[TCShowUser alloc]init];
  1763. showUser.uid = model.user_id;
  1764. showUser.avatar = model.head_image;
  1765. item.host = showUser;
  1766. if (self.BuguLive.liveState.isInPubViewController)
  1767. {
  1768. [[NSNotificationCenter defaultCenter] postNotificationName:@"pushLiveView" object:nil];
  1769. }
  1770. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  1771. //2020-1-7 小直播变大
  1772. [LiveCenterManager sharedInstance].itemModel=item;
  1773. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  1774. [[LiveCenterManager sharedInstance]showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:nil isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  1775. }];
  1776. }
  1777. //// 切换当前直播间
  1778. //- (void)changeNowLive
  1779. //{
  1780. // [FanweMessage alertHUD:ASLocalizedString(@"请退出当前直播间后重新尝试!")];
  1781. //}
  1782. #pragma mark 是否显示hud
  1783. - (void)isShowHud:(BOOL)isShow hideTime:(float)hideTime
  1784. {
  1785. if (isShow && !_HUD)
  1786. {
  1787. _HUD = [[BGHUDHelper sharedInstance] loading:@""];
  1788. if (hideTime)
  1789. {
  1790. [self performSelector:@selector(hideHud) withObject:nil afterDelay:hideTime];
  1791. }
  1792. }
  1793. else
  1794. {
  1795. [self hideHud];
  1796. }
  1797. }
  1798. - (void)hideHud
  1799. {
  1800. if (_HUD)
  1801. {
  1802. [[BGHUDHelper sharedInstance] stopLoading:_HUD];
  1803. _HUD = nil;
  1804. }
  1805. }
  1806. -(BogoNoNetworkView *)noNetworkView{
  1807. if (!_noNetworkView) {
  1808. _noNetworkView = [[NSBundle mainBundle]loadNibNamed:@"BogoNoNetworkView" owner:self options:nil].lastObject;
  1809. _noNetworkView.hidden = YES;
  1810. }
  1811. return _noNetworkView;
  1812. }
  1813. #pragma mark - BogoPrivacyPopViewDelegate
  1814. - (void)privacyPopView:(BogoPrivacyPopView *)privacyPopView didClickAgreeBtn:(UIButton *)sender{
  1815. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isAgreePrivacy"];
  1816. [[NSUserDefaults standardUserDefaults] synchronize];
  1817. [self doAfterAgreePrivacy];
  1818. }
  1819. - (void)privacyPopView:(BogoPrivacyPopView *)privacyPopView didClickUserAgreement:(UIButton *)sender{
  1820. BGBaseWebViewController *webVC = [BGBaseWebViewController webControlerWithUrlStr:[NSString stringWithFormat:@"%@",self.responseJson[@"user_agreement_link"]] isShowIndicator:NO isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  1821. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:webVC];
  1822. [self.window.rootViewController presentViewController:nav animated:YES completion:nil];
  1823. }
  1824. - (void)privacyPopView:(BogoPrivacyPopView *)privacyPopView didClickPrivacyAgreement:(UIButton *)sender{
  1825. BGBaseWebViewController *webVC = [BGBaseWebViewController webControlerWithUrlStr:[NSString stringWithFormat:@"%@",self.responseJson[@"privacy_link"]] isShowIndicator:NO isShowNavBar:YES isShowBackBtn:YES isShowCloseBtn:NO];
  1826. BGNavigationController *nav = [[BGNavigationController alloc]initWithRootViewController:webVC];
  1827. [self.window.rootViewController presentViewController:nav animated:YES completion:nil];
  1828. }
  1829. - (BogoPrivacyPopView *)privacyPopView{
  1830. if (!_privacyPopView) {
  1831. _privacyPopView = [[NSBundle mainBundle] loadNibNamed:@"BogoPrivacyPopView" owner:nil options:nil].lastObject;
  1832. _privacyPopView.delegate = self;
  1833. }
  1834. return _privacyPopView;
  1835. }
  1836. -(void)showNesBarRedNum{
  1837. UIWindow *window = [UIApplication sharedApplication].keyWindow;
  1838. UITabBarController *tabBarController = (UITabBarController *)window.rootViewController;
  1839. UITabBar *tabBar = tabBarController.tabBar;
  1840. // dispatch_async(dispatch_get_main_queue(), ^{
  1841. UITabBarItem *itme = [tabBar.items objectAtIndex:3];
  1842. SFriendObj *xxx = nil;
  1843. // [SFriendObj getMyFriendMsgList:0
  1844. // lastObj:xxx
  1845. // block:^(SResBase *resb, NSArray *all, int unReadNum) {
  1846. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  1847. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  1848. [parmDict setObject:@"unread_messages" forKey:@"act"];
  1849. [[NetHttpsManager manager]POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  1850. if ([[responseJson valueForKey:@"status"]integerValue] == 1) {
  1851. BogoNewsTabNumModel *model = [BogoNewsTabNumModel modelWithDictionary:[responseJson valueForKey:@"data"]];
  1852. [SFriendObj getAllUnReadCountComplete:^(int num) {
  1853. if ((model.bzone_reply + model.bzone_like + num) == 0) {
  1854. itme.badgeValue = nil;
  1855. }else{
  1856. dispatch_async(dispatch_get_main_queue(), ^{
  1857. itme.badgeValue = [NSString stringWithFormat:@"%ld",model.bzone_reply + model.bzone_like + num + model.msg.count];
  1858. });
  1859. }
  1860. }];
  1861. // self.headView.model = model;
  1862. }
  1863. } FailureBlock:^(NSError *error) {
  1864. }];
  1865. // });
  1866. }
  1867. @end