AppDelegate.m 85 KB

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