AppDelegate.m 84 KB

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