AppDelegate.m 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069
  1. //
  2. // AppDelegate.m
  3. // aiim
  4. //
  5. // Created by gan on 2025/2/27.
  6. //
  7. #import "AppDelegate.h"
  8. #import "UDManager.h"
  9. #import <UserNotifications/UserNotifications.h>
  10. #import <PushKit/PushKit.h>
  11. #import "CallKit/CallKit.h"
  12. #import <AFNetworking/AFNetworkReachabilityManager.h>
  13. #import "UserNetApi.h"
  14. #import "CryptoAES.h"
  15. #import "GWebSocket.h"
  16. #import "GDBManager.h"
  17. #import "APPLocker.h"
  18. #import "JSGController.h"
  19. #import "LoginStateManager.h"
  20. #import "FloatingWindow.h"
  21. #import "ChatIndexController.h"
  22. #import "ChatController.h"
  23. #import "ChatListStore.h"
  24. #import "ChatsStore.h"
  25. #import "OSSManager.h"
  26. #import <Bugly/Bugly.h>
  27. #ifdef DEBUG
  28. #import <DoraemonKit/DoraemonManager.h>
  29. #endif
  30. @import JitsiMeetSDK;
  31. @interface AppDelegate ()<UNUserNotificationCenterDelegate,PKPushRegistryDelegate,CXProviderDelegate>
  32. {
  33. BOOL _isReachable;
  34. }
  35. @property (nonatomic, strong) CXProvider *callProvider;
  36. @property (nonatomic) NSUUID *uuid;
  37. @property (nonatomic) NSDictionary *msg;
  38. @property (strong, nonatomic) NSString *bgMark;
  39. @property (nonatomic) BOOL isTokenCleared;
  40. @property (strong, nonatomic) FloatingWindow *floatWindow;
  41. @property (nonatomic, strong) JSGController * _Nullable jsyuyinctr;
  42. @property (nonatomic) BOOL isNotification;
  43. @property (nonatomic, assign) NSInteger badgeCount;
  44. @property (nonatomic, assign) NSInteger addFriendBadgeCount;
  45. @end
  46. @implementation AppDelegate
  47. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  48. // Override point for customization after application launch.
  49. app = self;
  50. BuglyConfig *config = [[BuglyConfig alloc] init];
  51. config.reportLogLevel = BuglyLogLevelVerbose;
  52. [Bugly startWithAppId:@"1d9e6b546a" config:config];
  53. self.isJitsiMeet=false;
  54. _isNotification=false;
  55. self.shouldShowLock = YES;
  56. self.bgMark=@"";
  57. [self initJSMSDK];
  58. [self setupListener];
  59. [self checkLoginState:launchOptions];
  60. [self registerPushright];
  61. [self setupCallProvider];
  62. [self startNetworkReachability];
  63. _isTokenCleared=YES;
  64. _floatWindow = [[FloatingWindow alloc] initWithFrame:self.window.bounds];
  65. [_floatWindow hide];
  66. self.bgMark = @"";
  67. NSLog(@"didFinishLaunchingWithOptions------");
  68. AVAudioSession *session = [AVAudioSession sharedInstance];
  69. [session setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVoiceChat options:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:nil];
  70. [session setActive:YES error:nil];
  71. #ifdef DEBUG
  72. //默认
  73. [[DoraemonManager shareInstance] install];
  74. // 或者使用传入位置,解决遮挡关键区域,减少频繁移动
  75. //[[DoraemonManager shareInstance] installWithStartingPosition:CGPointMake(66, 66)];
  76. #endif
  77. return YES;
  78. }
  79. -(void)applicationDidBecomeActive:(UIApplication *)application{
  80. NSLog(@"applicationDidBecomeActive");
  81. if(self.isLogin){
  82. [self sartWebsocket];
  83. if(self.isJitsiMeet){
  84. [_floatWindow viewInFload:0];
  85. }
  86. [self showLockScreen];
  87. if(!_isNotification){
  88. if ([[self.window jk_currentViewController] isKindOfClass:UITabBarController.class]){
  89. UITabBarController * tabbarVc= (UITabBarController *)[self.window jk_currentViewController];
  90. if (tabbarVc.selectedIndex==0) {
  91. ChatIndexController * chatListVc = tabbarVc.viewControllers[0];
  92. if (chatListVc) {
  93. [chatListVc reloadList];
  94. }
  95. }
  96. }
  97. else{
  98. [Bugly reportException:[NSException exceptionWithName:@"applicationDidBecomeActive1" reason:@"1" userInfo:nil]];
  99. if ([[self.window jk_currentViewController] isKindOfClass:ChatController.class]) {
  100. ChatController * currentChatVc = (ChatController *)[self.window jk_currentViewController];
  101. [currentChatVc reloadAllData];
  102. [Bugly reportException:[NSException exceptionWithName:@"applicationDidBecomeActive2" reason:@"2" userInfo:nil]];
  103. }
  104. }
  105. }
  106. }
  107. }
  108. -(void)applicationDidEnterBackground:(UIApplication *)application{
  109. NSLog(@"applicationDidEnterBackground");
  110. _isNotification=false;
  111. // [self endWebsocket];
  112. __block UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
  113. [application endBackgroundTask:bgTask];
  114. bgTask = UIBackgroundTaskInvalid;
  115. }];
  116. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  117. // 在这里保持任务运行或等待事件,例如等待来电等。
  118. [application endBackgroundTask:bgTask];
  119. bgTask = UIBackgroundTaskInvalid;
  120. });
  121. // 应用进入后台时标记需要显示锁屏
  122. if(self.isJitsiMeet == YES){
  123. [self.window endEditing:YES];
  124. }
  125. else{
  126. if ([[APPLocker sharedLocker] isPasswordSet] && [[APPLocker sharedLocker] isLockEnabled]) {
  127. self.shouldShowLock = YES;
  128. }
  129. }
  130. }
  131. + (instancetype)sharedInstance {
  132. return app;
  133. }
  134. -(void)initJSMSDK{
  135. JitsiMeetConferenceOptions *defaultOptions
  136. = [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
  137. builder.serverURL = [NSURL URLWithString:JitsiMeetSV];
  138. [builder setFeatureFlag:@"welcomepage.enabled" withBoolean:NO];
  139. [builder setFeatureFlag:@"prejoinPage.enabled" withBoolean:NO];
  140. //媒体流优化
  141. builder.audioMuted = NO; // 提前初始化音频模块
  142. builder.videoMuted = NO; // 提前初始化视频模块
  143. //禁用非必要功能(减少初始化负载)
  144. [builder setFeatureFlag:@"add-people.enabled" withBoolean:NO];
  145. [builder setFeatureFlag:@"invite.enabled" withBoolean:NO];
  146. [builder setFeatureFlag:@"live-streaming.enabled" withBoolean:NO];
  147. [builder setFeatureFlag:@"video-share.enabled" withBoolean:NO];
  148. [builder setFeatureFlag:@"call-integration.enabled" withBoolean:NO];
  149. [builder setFeatureFlag:@"startWithAudioMuted" withBoolean:NO];
  150. [builder setFeatureFlag:@"recording.enabled" withBoolean:NO];
  151. [builder setFeatureFlag:@"kick-out.enabled" withBoolean:NO];
  152. [builder setFeatureFlag:@"security-options.enabled" withBoolean:NO];
  153. //
  154. // //网络传输层加速
  155. // [builder setConfigOverride:@"disableSimulcast" withBoolean:YES];
  156. // [builder setFeatureFlag:@"reconnect.enabled" withBoolean:YES];
  157. // [builder setFeatureFlag:@"websocket-keep-alive.enabled" withBoolean:YES];
  158. // [builder setFeatureFlag:@"network-monitor.enabled" withBoolean:YES];
  159. // [builder setConfigOverride:@"iceTransportPolicy" withValue:@"relay"];
  160. // // 界面渲染加速
  161. // [builder setFeatureFlag:@"filmstrip.enabled" withBoolean:NO];
  162. // [builder setFeatureFlag:@"tile-view.enabled" withBoolean:NO];
  163. //
  164. // [builder setFeatureFlag:@"pip.enabled" withBoolean:NO];
  165. // [builder setFeatureFlag:@"chat.enabled" withBoolean:NO];
  166. [builder setConfigOverride:@"toolbarButtons" withArray:@[@"microphone",@"camera"]];
  167. }];
  168. [JitsiMeet sharedInstance].defaultConferenceOptions = defaultOptions;
  169. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  170. _jsyuyinctr = [board instantiateViewControllerWithIdentifier:@"JSGController"];
  171. _jsyuyinctr.modalPresentationStyle = UIModalPresentationFullScreen;
  172. }
  173. -(void)setupListener{
  174. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLoginSucc) name:nkonLoginSucc object:nil];
  175. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLogoutSucc) name:nkonLogoutSucc object:nil];
  176. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addFriend) name:nkonAddFriendNote object:nil];;
  177. }
  178. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  179. NSLog(@"Failed to get token, error: %@", error);
  180. }
  181. #pragma mark push token voip token
  182. -(void)registerPushright{
  183. // 请求推送权限
  184. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  185. center.delegate = self; // 设置代理以处理通知相关事件
  186. [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvidesAppNotificationSettings) completionHandler:^(BOOL granted, NSError * _Nullable error) {
  187. if (granted) {
  188. // 用户授权成功
  189. dispatch_async(dispatch_get_main_queue(), ^{
  190. [[UIApplication sharedApplication] registerForRemoteNotifications];
  191. });
  192. } else {
  193. // 用户授权失败
  194. }
  195. }];
  196. PKPushRegistry *registry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
  197. registry.delegate = self;
  198. registry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
  199. }
  200. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  201. // 将NSData转换为NSString以便于传输或存储
  202. NSRange range = NSMakeRange(0, 16); // 例如,从索引0开始,获取前10个字节
  203. NSData *subData1 = [deviceToken subdataWithRange:range];
  204. range = NSMakeRange(16, 16);
  205. NSData *subData2 = [deviceToken subdataWithRange:range];
  206. range = NSMakeRange(24, 32);
  207. NSString *token1=[[subData1 description] substringWithRange:range];
  208. NSString *token2=[[subData2 description] substringWithRange:range];
  209. NSString *token = [NSString stringWithFormat:@"%@%@",token1,token2];
  210. NSLog(@"%@",token);
  211. // 将token发送到你的服务器或其他需要的地方
  212. [UDManager.shareInstance setSDManager:token key:dkpushtoken];
  213. NSString *bgMark = [NSString stringWithFormat:@"推送token:%ld",token.length];
  214. [Bugly reportException:[NSException exceptionWithName:bgMark reason:@"" userInfo:nil]];
  215. if(self.isLogin){
  216. [self updivicetoken];
  217. }
  218. }
  219. #pragma mark login sttate
  220. - (void)checkLoginState:(NSDictionary *)launchOptions{
  221. [[LoginStateManager sharedManager] getUserInfo];
  222. [LoginStateManager sharedManager].checkLoginState = ^(BOOL isLogin) {
  223. if (isLogin) {
  224. self.isLogin =TRUE;
  225. [self updivicetoken];
  226. [self updiviceVoIPtoken];
  227. [self sartWebsocket];
  228. [self openFMDB];
  229. [self openMainController];
  230. // 检查是否需要显示启动锁屏
  231. if ([[APPLocker sharedLocker] isPasswordSet] && [[APPLocker sharedLocker] isLockEnabled]) {
  232. [self showLockScreen];
  233. }
  234. else{
  235. self.shouldShowLock = NO;
  236. }
  237. }else{
  238. [self openLoginController];
  239. }
  240. };
  241. }
  242. -(void)updivicetoken{
  243. NSString *token =[UDManager.shareInstance getSDManager:dkpushtoken];
  244. NSDictionary *usinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  245. NSLog(@"dkpushtoken:%@",token);
  246. NSDictionary *ud=@{
  247. @"registrationId": token?:@"",
  248. @"userId":usinfo[@"id"]?:@"",
  249. @"platformType":@"i"
  250. };
  251. NSString *bgMark = [NSString stringWithFormat:@"上传推送token:%ld",token.length];
  252. [Bugly reportException:[NSException exceptionWithName:bgMark reason:@"" userInfo:nil]];
  253. [UserNetApi setUserinfo:ud succ:^(int code, NSDictionary * res) {
  254. self->_isTokenCleared=NO;
  255. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:res options:0 error:nil];
  256. if (!jsonData) {
  257. NSLog(@"Got an error:");
  258. } else {
  259. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  260. NSLog(@"%@", jsonString); // 输出:{"name":"John","age":25}
  261. }
  262. } fail:^(NSError * _Nonnull error) {
  263. NSLog(@"--%@",error);
  264. }];
  265. }
  266. -(void)updiviceVoIPtoken{
  267. NSString *token =[UDManager.shareInstance getSDManager:dkvoiptoken];
  268. NSDictionary *usinfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  269. NSLog(@"dkvoiptoken:%@",token);
  270. NSString *bgMark = [NSString stringWithFormat:@"上传 voip 推送token:%ld",token.length];
  271. [Bugly reportException:[NSException exceptionWithName:bgMark reason:@"" userInfo:nil]];
  272. if([token isKindOfClass:[NSNull class]]){
  273. return;
  274. }
  275. NSDictionary *ud=@{
  276. @"voipTk": token?:@"",
  277. @"userId":usinfo[@"id"]?:@"",
  278. @"platformType":@"i"
  279. };
  280. [UserNetApi setUserinfo:ud succ:^(int code, NSDictionary * res) {
  281. NSLog(@"updiviceVoIPtoken:%@",[res description]);
  282. self->_isTokenCleared=NO;
  283. } fail:^(NSError * _Nonnull error) {
  284. NSLog(@"--%@",error);
  285. }];
  286. }
  287. - (void)addFriend{
  288. self.addFriendBadgeCount++;
  289. NSLog(@"addFriend------------:%ld", self.addFriendBadgeCount);
  290. [self updateTabBarBadgeValueAtIndex:1 badgeCount:self.addFriendBadgeCount];
  291. [self sendAddFreindNotice];
  292. [self updateApplicationIconBadgeNumber];
  293. }
  294. - (void)sendAddFreindNotice {
  295. // 发送本地通知
  296. UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
  297. content.title = @"好友申请";
  298. content.body = @"您收到了新的好友申请";
  299. content.sound = [UNNotificationSound defaultSound];
  300. content.badge = @(self.addFriendBadgeCount);
  301. UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:0.1 repeats:NO];
  302. NSString *identifier = [NSString stringWithFormat:@"FriendRequest_%@", [[NSUUID UUID] UUIDString]];
  303. UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];
  304. [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
  305. if (error) {
  306. NSLog(@"发送本地通知失败: %@", error);
  307. } else {
  308. NSLog(@"发送本地通知成功");
  309. }
  310. }];
  311. }
  312. - (void)updateApplicationIconBadgeNumber {
  313. NSInteger total = self.badgeCount + self.addFriendBadgeCount;
  314. if (@available(iOS 16.0, *)) {
  315. [[UNUserNotificationCenter currentNotificationCenter] setBadgeCount:total withCompletionHandler:^(NSError * _Nullable error) {
  316. if (error) {
  317. NSLog(@"设置消息未读数 error: %@", error);
  318. }
  319. }];
  320. } else {
  321. // Fallback on earlier versions
  322. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:total];
  323. }
  324. }
  325. - (void)resetAddFriendBadgeCount {
  326. self.addFriendBadgeCount = 0;
  327. [self updateTabBarBadgeValueAtIndex:1 badgeCount:0];
  328. [self updateApplicationIconBadgeNumber];
  329. }
  330. - (void)resetBadgeCount {
  331. self.badgeCount = 0;
  332. [self updateApplicationIconBadgeNumber];
  333. }
  334. - (void)updateTabBarBadgeValueAtIndex:(NSInteger)index badgeCount:(NSInteger)badgeCount {
  335. UITabBarController * tabbarVc = (UITabBarController *)self.window.rootViewController;
  336. if(index < 0 || index >= tabbarVc.tabBar.items.count){
  337. return;
  338. }
  339. UITabBarItem *tabBarItem = tabbarVc.tabBar.items[index];
  340. NSString *badgeValue = badgeCount > 0 ? [NSString stringWithFormat:@"%ld", badgeCount] : nil;
  341. badgeValue = badgeValue.length > 2 ? @"99+" : badgeValue;
  342. tabBarItem.badgeValue = badgeValue;
  343. }
  344. - (void)updateBadgeCount:(NSInteger)badgeCount {
  345. self.badgeCount = badgeCount;
  346. [self updateApplicationIconBadgeNumber];
  347. }
  348. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  349. NSLog(@"Received notification: %@", userInfo);
  350. NSDictionary *temp =userInfo[@"imMsg"];
  351. if(temp){
  352. if ([temp jk_hasKey:@"addFriend"]) {
  353. [self addFriend];
  354. }
  355. NSDictionary *msg =temp[@"message"];
  356. NSString *msgtype=msg[@"msgtype"];
  357. if([msgtype isEqualToString:@"close"]){
  358. if(self.uuid!=nil){
  359. NSString *fromId = self.msg[@"fromId"];
  360. if ( [fromId isEqualToString:msg[@"fromId"]]) {
  361. [self.callProvider reportCallWithUUID:self.uuid endedAtDate:nil reason:CXCallEndedReasonDeclinedElsewhere];
  362. self.uuid = nil;
  363. self.msg =nil;
  364. }
  365. }
  366. }
  367. }
  368. // 处理推送消息,例如更新UI或处理数据等
  369. completionHandler(UIBackgroundFetchResultNewData);
  370. }
  371. #pragma mark - PKPushRegistryDelegate
  372. - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
  373. // 处理推送凭证更新,例如保存 token 到服务器
  374. NSLog(@"Credentials updated: %@", credentials.token);
  375. NSData *deviceToken = (NSData *)credentials.token;
  376. NSRange range = NSMakeRange(0, 16); // 例如,从索引0开始,获取前10个字节
  377. NSData *subData1 = [deviceToken subdataWithRange:range];
  378. range = NSMakeRange(16, 16);
  379. NSData *subData2 = [deviceToken subdataWithRange:range];
  380. range = NSMakeRange(24, 32);
  381. //NSLog(@"subData1: %@",subData1);
  382. //NSLog(@"subData2: %@",subData2);
  383. NSString *token1=[[subData1 description] substringWithRange:range];
  384. NSString *token2=[[subData2 description] substringWithRange:range];
  385. NSString *token = [NSString stringWithFormat:@"%@%@",token1,token2];
  386. NSLog(@"%@",token);
  387. //将token发送到你的服务器或其他需要的地方
  388. NSString *bgMark = [NSString stringWithFormat:@"voip token:%ld",token.length];
  389. [Bugly reportException:[NSException exceptionWithName:bgMark reason:@"" userInfo:nil]];
  390. [UDManager.shareInstance setSDManager:token key:dkvoiptoken];
  391. if(self.isLogin){
  392. [self updiviceVoIPtoken];
  393. }
  394. }
  395. - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion{
  396. NSDictionary * temp =payload.dictionaryPayload;
  397. temp =temp[@"business"];
  398. temp=temp[@"incomingCallParams"];
  399. NSString *name =temp[@"localizedCallerName"];
  400. NSLog(@"name:%@",name);
  401. temp =payload.dictionaryPayload;
  402. temp =temp[@"imMsg"];
  403. if(self.uuid!=nil||self.isJitsiMeet){//通知对方正忙,功能需要补上
  404. [self isBUSYNow:temp[@"message"]];
  405. return;
  406. }
  407. self.msg = temp[@"message"];
  408. NSLog(@"self.msg-----:%@",self.msg);
  409. CXCallUpdate * callUpdate = [[CXCallUpdate alloc]init];
  410. callUpdate.supportsGrouping = YES;
  411. callUpdate.supportsDTMF = YES;
  412. callUpdate.hasVideo = YES;
  413. callUpdate.supportsHolding = YES;
  414. [callUpdate setLocalizedCallerName:name];
  415. CXHandle * handle = [[CXHandle alloc]initWithType:CXHandleTypePhoneNumber value:@""];
  416. callUpdate.remoteHandle = handle;
  417. self.uuid = [NSUUID UUID];
  418. [self.callProvider reportNewIncomingCallWithUUID:self.uuid update:callUpdate completion:^(NSError * _Nullable error) {
  419. NSLog(@"%@",error);
  420. }];
  421. completion();
  422. }
  423. -(void)isBUSYNow:(NSDictionary *)msg{
  424. NSDate *now = [NSDate date];
  425. NSTimeInterval trt = [now timeIntervalSince1970];
  426. NSInteger time = trt*1000;
  427. NSString *strtime = [NSString stringWithFormat:@"%ld",(long)time];
  428. NSDictionary *callMsg = @{
  429. @"code":SendCode_WEBRTC_DFBUSY,
  430. @"message": @{
  431. @"chatId":msg[@"fromId"],
  432. @"fromId":msg[@"chatId"],
  433. @"type":@"0",
  434. @"messageType":MessageType_DFBUSY,
  435. @"timestamp":strtime,
  436. @"payload":@""
  437. }
  438. };
  439. NSError *error;
  440. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:callMsg options:0 error:&error];
  441. if (!jsonData) {
  442. NSLog(@"Got an error: %@", error);
  443. } else {
  444. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  445. NSLog(@"%@", jsonString); // 输出: {"name":"John","age":25}
  446. [GWebSocket.shareInstance sendMsg:jsonString];
  447. }
  448. }
  449. #pragma mark - CXProviderDelegate Methods
  450. - (void)setupCallProvider {
  451. // 创建配置对象
  452. CXProviderConfiguration *config = [[CXProviderConfiguration alloc] init];
  453. config.supportsVideo = YES; // 是否支持视频通话
  454. config.maximumCallGroups = 1; // 最大通话组数
  455. config.maximumCallsPerCallGroup = 1; // 每个通话组的最大通话数
  456. config.supportedHandleTypes = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:CXHandleTypeGeneric],[NSNumber numberWithInt:CXHandleTypePhoneNumber], nil];//[NSSet setWithArray:@[CXHandleTypePhoneNumber]]; // 支持的号码类型
  457. config.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"AppIcon"]); // 应用图标
  458. config.ringtoneSound = @"ringtone.aiff"; // 铃声文件(可选)
  459. // 创建CXProvider实例
  460. self.callProvider = [[CXProvider alloc] initWithConfiguration:config];
  461. [self.callProvider setDelegate:self queue:nil];
  462. //self.callRoomMap = [NSMutableDictionary dictionary];
  463. }
  464. - (void)providerDidReset:(CXProvider *)provider {
  465. NSLog(@"Provider reset");
  466. }
  467. - (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action {
  468. // 开始通话的逻辑,如连接服务器等
  469. NSLog(@"performStartCallAction:%@",action);
  470. [action fulfill]; // 当通话开始时调用此方法完成action
  471. }
  472. -(void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action{
  473. [self reciveVoip];
  474. //使用GCD创建一个在3秒后执行的定时器
  475. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  476. NSLog(@"performAnswerCallAction:%@",action);
  477. if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
  478. // 应用已经解锁并且在前台
  479. if(self.uuid){
  480. [self.callProvider reportCallWithUUID:self.uuid endedAtDate:nil reason:CXCallEndedReasonDeclinedElsewhere];
  481. self.msg = nil;
  482. self.uuid = nil;
  483. }
  484. }
  485. });
  486. }
  487. -(void)provider:(CXProvider *)provider timedOutPerformingAction:(CXAction *)action{
  488. if (!self.uuid) {
  489. return;
  490. }
  491. [self.callProvider reportCallWithUUID:self.uuid endedAtDate:nil reason:CXCallEndedReasonDeclinedElsewhere];
  492. self.msg = nil;
  493. self.uuid = nil;
  494. NSLog(@"timedOutPerformingAction:%@",action);
  495. }
  496. - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action {
  497. // 挂断电话的逻辑,如断开服务器连接等
  498. NSLog(@"performEndCallAction:%@",action);
  499. NSDate *now = [NSDate date];
  500. NSTimeInterval trt = [now timeIntervalSince1970];
  501. NSInteger time = trt*1000;
  502. NSString *strtime = [NSString stringWithFormat:@"%ld",(long)time];
  503. NSDictionary *callMsg = @{
  504. @"code":@"9",
  505. @"message": @{
  506. @"chatId":self.msg[@"fromId"],
  507. @"fromId":self.msg[@"chatId"],
  508. @"type":@"0",
  509. @"msgtype":@"close",
  510. @"timestamp":strtime,
  511. @"payload":self.msg[@"payload"]
  512. }
  513. };
  514. NSError *error;
  515. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:callMsg options:0 error:&error];
  516. if (!jsonData) {
  517. NSLog(@"Got an error: %@", error);
  518. } else {
  519. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  520. NSLog(@"%@", jsonString); // 输出: {"name":"John","age":25}
  521. [GWebSocket.shareInstance sendMsg:jsonString];
  522. }
  523. self.uuid = nil;
  524. self.msg =nil;
  525. [action fulfill]; // 当通话结束时调用此方法完成action
  526. }
  527. -(void)reciveVoip{
  528. NSLog(@"reciveVoip-------------1");
  529. if(self.msg){
  530. NSNumber *conetType = self.msg[@"conetType"];
  531. NSLog(@"vidio:%@",self.msg[@"payload"]);
  532. BOOL audioOnly = YES;
  533. if(conetType.boolValue){
  534. audioOnly = NO;
  535. }
  536. else{
  537. audioOnly = YES;
  538. }
  539. [self startJSCall:self.msg[@"fromId"] room:self.msg[@"payload"] isCaller:NO audioOnly:audioOnly];
  540. }
  541. }
  542. //开启悬浮窗拨打方式
  543. -(void)startJSCall:(NSString *_Nonnull)chatId room:(NSString *_Nonnull)roomId isCaller:(BOOL)isCaller audioOnly:(BOOL)audioOnly{
  544. self.isJitsiMeet = YES;
  545. if(_jsyuyinctr){
  546. _jsyuyinctr.chatId = chatId.copy;
  547. _jsyuyinctr.room = roomId.copy;
  548. _jsyuyinctr.audioOnly = audioOnly;
  549. _jsyuyinctr.isCaller = isCaller;
  550. }
  551. else{
  552. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  553. _jsyuyinctr = [board instantiateViewControllerWithIdentifier:@"JSGController"];
  554. _jsyuyinctr.modalPresentationStyle = UIModalPresentationFullScreen;
  555. _jsyuyinctr.chatId = chatId.copy;
  556. _jsyuyinctr.room = roomId.copy;
  557. _jsyuyinctr.audioOnly = audioOnly;
  558. _jsyuyinctr.isCaller = isCaller;
  559. }
  560. NSLog(@"startJSCall roomId:%@",roomId);
  561. [_floatWindow showView:_jsyuyinctr.view];
  562. [_jsyuyinctr startJitsiMeetCall];
  563. [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
  564. }
  565. -(void)floadinSmWindow:(NSInteger )type{
  566. if(type!=0){
  567. [_floatWindow viewInFload:type];
  568. }
  569. }
  570. +(void)closeVoip{
  571. if(app.uuid!=nil){
  572. [app.callProvider reportCallWithUUID:app.uuid endedAtDate:nil reason:CXCallEndedReasonDeclinedElsewhere];
  573. app.uuid = nil;
  574. app.msg =nil;
  575. }
  576. }
  577. +(void)JitsiMeetState:(BOOL)state{
  578. app.isJitsiMeet=state;
  579. if(!state){
  580. if(app.shouldShowLock){
  581. [app showLockScreen];
  582. }
  583. else{
  584. [app.floatWindow hide];
  585. }
  586. }
  587. }
  588. +(void)unlockAPP{
  589. app.shouldShowLock=NO;
  590. }
  591. +(void)changeFloadViewState:(BOOL)state{
  592. if (state) {
  593. [app.floatWindow hide];
  594. }
  595. else{
  596. if ([[APPLocker sharedLocker] isPasswordSet] && [[APPLocker sharedLocker] isLockEnabled]) {
  597. [app.floatWindow show:1];
  598. }
  599. }
  600. }
  601. #pragma mark 用户点击消息推送或滑动
  602. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  603. completionHandler(UNNotificationPresentationOptionList | UNNotificationPresentationOptionBanner |
  604. UNNotificationPresentationOptionSound |
  605. UNNotificationPresentationOptionBadge);
  606. }
  607. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)(void))completionHandler {
  608. // 处理用户对通知的响应(点击、滑动等)
  609. if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) {
  610. // 用户点击了通知
  611. NSDictionary *userInfo = response.notification.request.content.userInfo;
  612. [self handleNotification:userInfo];
  613. NSLog(@"userInfo: %@", userInfo);
  614. } else if ([response.actionIdentifier isEqualToString:@"customActionIdentifier"]) {
  615. // 处理自定义动作(如果有的话)
  616. }
  617. completionHandler(); // 调用完成处理程序以结束操作
  618. }
  619. - (void)handleNotification:(NSDictionary *)userInfo {
  620. NSDictionary * tempDict = userInfo[@"imMsg"];
  621. NSDictionary * imMsg = tempDict[@"message"];
  622. _isNotification=true;
  623. NSMutableDictionary * mutablemsg = imMsg.mutableCopy;
  624. NSLog(@"------mutablemsg:%@",mutablemsg);
  625. NSDictionary * user = [UDManager.shareInstance getDDManager:dkuserinfo];
  626. if([user[@"id"] isEqual:imMsg[@"fromId"]]){
  627. [mutablemsg setObject:@"true" forKey:@"mine"];
  628. }else{
  629. if([Friendchat isEqual:imMsg[@"type"]]){
  630. [mutablemsg setObject:imMsg[@"fromId"] forKey:@"chatId"];
  631. }
  632. }
  633. if (imMsg) {
  634. if (![LoginStateManager sharedManager].isLoggedIn) {
  635. return;
  636. }
  637. if ([imMsg jk_hasKey:@"addFriend"]) {
  638. return;
  639. }
  640. NSString *strtype = mutablemsg[@"type"];
  641. NSInteger type = [strtype integerValue];
  642. NSString *chatId = mutablemsg[@"chatId"];
  643. NSString *titlename = mutablemsg[@"fromName"]?:@"";
  644. NSString *avatar = mutablemsg[@"fromAvatar"]?:@"";
  645. // NSLog(@"top className:%@",[[self.window jk_topMostController] class]);
  646. // NSLog(@"current className:%@",[[self.window jk_currentViewController] class]);
  647. if ([[self.window jk_currentViewController] isKindOfClass:ChatController.class]) {
  648. ChatController * currentChatVc = (ChatController *)[self.window jk_currentViewController];
  649. if (![currentChatVc.chatId isEqualToString:mutablemsg[@"chatId"]]) {
  650. currentChatVc.chatId = chatId;
  651. currentChatVc.type = type;
  652. currentChatVc.titlename = titlename;
  653. currentChatVc.avatar = avatar;
  654. [currentChatVc reloadAllData];
  655. return;
  656. }
  657. else{
  658. currentChatVc.chatId = chatId;
  659. currentChatVc.type = type;
  660. currentChatVc.titlename = titlename;
  661. currentChatVc.avatar = avatar;
  662. [currentChatVc reloadAllData];
  663. return;
  664. }
  665. }
  666. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  667. ChatController *chatctr = [board instantiateViewControllerWithIdentifier:@"ChatController"];
  668. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  669. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  670. chatctr.chatId = chatId;
  671. chatctr.type = type;
  672. chatctr.titlename = titlename;
  673. chatctr.avatar = avatar;
  674. UITabBarController * tabbarVc = (UITabBarController *)self.window.rootViewController;
  675. ChatIndexController * chatListVc = tabbarVc.viewControllers[0];
  676. if (chatListVc) {
  677. [chatListVc presentViewController:uiNavC animated:YES completion:nil];
  678. }
  679. }
  680. }
  681. #pragma mark -user state and note
  682. -(void)onLoginSucc{
  683. self.isLogin =TRUE;
  684. [self openFMDB];
  685. [self openMainController];
  686. [self updivicetoken];
  687. [self updiviceVoIPtoken];
  688. [self sartWebsocket];
  689. }
  690. -(void)onLogoutSucc{
  691. self.isLogin =false;
  692. NSLog(@"1-----------------1");
  693. // [GDBManager.shareInstance delLocalmsglistTable:userid];
  694. // [GDBManager.shareInstance delchatlistTable:nil fail:nil];
  695. // [GDBManager.shareInstance deleteDB];
  696. [UDManager.shareInstance removeUDManager:gkeytoken];
  697. [UDManager.shareInstance removeUDManager:dkuserloginId];
  698. [UDManager.shareInstance removeUDManager:dkuserinfo];
  699. [UDManager.shareInstance removeUDManager:dkuserId];
  700. [self clearVoipToken];
  701. [self openLoginController];
  702. [self endWebsocket];
  703. [self resetBadgeCount];
  704. [self resetAddFriendBadgeCount];
  705. }
  706. -(void)clearVoipToken{
  707. NSString *voiptoken = [UDManager.shareInstance getSDManager:dkvoiptoken];
  708. NSLog(@"voiptoken:%@",voiptoken);
  709. if([voiptoken isKindOfClass:[NSString class]]&&voiptoken.length>10){
  710. NSDictionary *dic = @{
  711. @"voipTk":voiptoken
  712. };
  713. [UserNetApi clearVoipTk:dic succ:^(int code, NSDictionary * res) {
  714. NSLog(@"clearVoipTk:%@",res);
  715. self->_isTokenCleared=YES;
  716. } fail:^(NSError * _Nonnull error) {
  717. }];
  718. }
  719. NSString *pushtoken = [UDManager.shareInstance getSDManager:dkpushtoken];
  720. NSLog(@"voiptoken:%@",pushtoken);
  721. if([pushtoken isKindOfClass:[NSString class]]&&pushtoken.length>10){
  722. NSDictionary *dic = @{
  723. @"registrationId":pushtoken
  724. };
  725. [UserNetApi clearRegistrationId:dic succ:^(int code, NSDictionary * res) {
  726. NSLog(@"clearRegistrationId:%@",res);
  727. self->_isTokenCleared=YES;
  728. } fail:^(NSError * _Nonnull error) {
  729. }];
  730. }
  731. }
  732. #pragma mark mainControllor Manager
  733. -(void)openMainController{
  734. NSLog(@"openMainController");
  735. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  736. UITabBarController *tbc = [board instantiateViewControllerWithIdentifier:@"GTabBarController"];
  737. //UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tbc];
  738. NSArray *ctrs = tbc.viewControllers;
  739. //------------1
  740. UIViewController *time = ctrs[0];
  741. // 创建一个新的 UITabBarItem
  742. UIImage *index = [[UIImage imageNamed:@"index"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  743. UIImage *index_cur = [[UIImage imageNamed:@"index_cur"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  744. UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"TabBarItem1", @"")
  745. image:index
  746. selectedImage:index_cur];
  747. // 设置标签文本
  748. tabBarItem.title = NSLocalizedString(@"TabBarItem1", @"");
  749. // 设置标签的文本颜色
  750. [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
  751. [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected];
  752. [time setTabBarItem:tabBarItem];
  753. //----------------2
  754. time = ctrs[1];
  755. // 创建一个新的 UITabBarItem
  756. UIImage *index1 = [[UIImage imageNamed:@"txl"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  757. UIImage *index_cur1 = [[UIImage imageNamed:@"txl_cur"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  758. UITabBarItem *tabBarItem1 = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"TabBarItem2", @"")
  759. image:index1
  760. selectedImage:index_cur1];
  761. // 设置标签文本
  762. tabBarItem1.title = NSLocalizedString(@"TabBarItem2", @"");
  763. // 设置标签的文本颜色
  764. [tabBarItem1 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
  765. [tabBarItem1 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected];
  766. [time setTabBarItem:tabBarItem1];
  767. //------------------3
  768. time = ctrs[2];
  769. // 创建一个新的 UITabBarItem
  770. UIImage *index2 = [[UIImage imageNamed:@"qunzu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  771. UIImage *index_cur2 = [[UIImage imageNamed:@"qunzu_cur"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  772. UITabBarItem *tabBarItem2 = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"TabBarItem3", @"")
  773. image:index2
  774. selectedImage:index_cur2];
  775. // 设置标签文本
  776. tabBarItem2.title = NSLocalizedString(@"TabBarItem3", @"");
  777. // 设置标签的文本颜色
  778. [tabBarItem2 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
  779. [tabBarItem2 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected];
  780. [time setTabBarItem:tabBarItem2];
  781. //------------------4
  782. time = ctrs[3];
  783. // 创建一个新的 UITabBarItem
  784. UIImage *index3 = [[UIImage imageNamed:@"wode"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  785. UIImage *index_cur3 = [[UIImage imageNamed:@"wode_cur"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  786. UITabBarItem *tabBarItem3 = [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"TabBarItem4", @"")
  787. image:index3
  788. selectedImage:index_cur3];
  789. // 设置标签文本
  790. tabBarItem3.title = NSLocalizedString(@"TabBarItem4", @"");
  791. // 设置标签的文本颜色
  792. [tabBarItem3 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
  793. [tabBarItem3 setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateSelected];
  794. [time setTabBarItem:tabBarItem3];
  795. self.window.rootViewController = tbc;
  796. }
  797. -(void)openLoginController{
  798. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  799. GLoginController *login = [board instantiateViewControllerWithIdentifier:@"LoginController"];
  800. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:login];
  801. self.window.rootViewController = nav;
  802. }
  803. #pragma mark openSocket
  804. -(void)sartWebsocket{
  805. NSLog(@"----------------sartWebsocket");
  806. [[GWebSocket shareInstance] connectWebSocket];
  807. }
  808. -(void)endWebsocket{
  809. [[GWebSocket shareInstance] closeWebSocket];
  810. }
  811. #pragma mark init DB
  812. -(void)openFMDB{
  813. [GDBManager.shareInstance createDatabase:^(NSArray * _Nullable array) {
  814. [GDBManager.shareInstance createLocalMSGtable:^(NSArray * _Nullable array) {
  815. } fail:^(NSString * _Nullable error) {
  816. }];
  817. [GDBManager.shareInstance createChattable:^(NSArray * _Nullable array) {
  818. } fail:^(NSString * _Nullable error) {
  819. }];
  820. [GDBManager.shareInstance createLastreadtimetable:^(NSArray * _Nullable array) {
  821. } fail:^(NSString * _Nullable error) {
  822. }];
  823. } fail:^(NSString * _Nullable error) {
  824. }];
  825. }
  826. #pragma mark - UISceneSession lifecycle
  827. //- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
  828. // // Called when a new scene session is being created.
  829. // // Use this method to select a configuration to create the new scene with.
  830. // return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
  831. //}
  832. //
  833. //
  834. //- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
  835. // // Called when the user discards a scene session.
  836. // // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
  837. // // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
  838. //}
  839. #pragma mark - Core Data stack
  840. @synthesize persistentContainer = _persistentContainer;
  841. - (NSPersistentContainer *)persistentContainer {
  842. // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.
  843. @synchronized (self) {
  844. if (_persistentContainer == nil) {
  845. _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"555IM"];
  846. [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {
  847. if (error != nil) {
  848. // Replace this implementation with code to handle the error appropriately.
  849. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  850. /*
  851. Typical reasons for an error here include:
  852. * The parent directory does not exist, cannot be created, or disallows writing.
  853. * The persistent store is not accessible, due to permissions or data protection when the device is locked.
  854. * The device is out of space.
  855. * The store could not be migrated to the current model version.
  856. Check the error message to determine what the actual problem was.
  857. */
  858. NSLog(@"Unresolved error %@, %@", error, error.userInfo);
  859. abort();
  860. }
  861. }];
  862. }
  863. }
  864. return _persistentContainer;
  865. }
  866. #pragma mark - Core Data Saving support
  867. - (void)saveContext {
  868. NSManagedObjectContext *context = self.persistentContainer.viewContext;
  869. NSError *error = nil;
  870. if ([context hasChanges] && ![context save:&error]) {
  871. // Replace this implementation with code to handle the error appropriately.
  872. // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
  873. NSLog(@"Unresolved error %@, %@", error, error.userInfo);
  874. abort();
  875. }
  876. }
  877. #pragma mark 检测网络状态
  878. -(void)startNetworkReachability {
  879. AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
  880. __weak typeof(manager) weakManager = manager;
  881. [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  882. BOOL isReachable = weakManager.isReachable;
  883. self->_isReachable = isReachable;
  884. NSLog(@"startNetworkReachability: %d", isReachable);
  885. if (isReachable) {
  886. } else {
  887. }
  888. }];
  889. [manager startMonitoring];
  890. }
  891. - (BOOL)isReachable {
  892. return _isReachable;
  893. }
  894. #pragma mark applock
  895. - (void)showLockScreen {
  896. // 确保在主线程执行
  897. if (self.shouldShowLock && [[APPLocker sharedLocker] isPasswordSet] && [[APPLocker sharedLocker] isLockEnabled]) {
  898. NSLog(@"showLockScreen--------------1");
  899. if (self.isJitsiMeet) {
  900. [_floatWindow viewInFload:0];
  901. return;
  902. }
  903. else{
  904. [_floatWindow show:1];
  905. }
  906. return;
  907. }
  908. if (!self.isJitsiMeet) {
  909. [_floatWindow hide];
  910. }
  911. }
  912. @end