|
@@ -10,8 +10,7 @@
|
|
|
#import <UserNotifications/UserNotifications.h>
|
|
#import <UserNotifications/UserNotifications.h>
|
|
|
#import <PushKit/PushKit.h>
|
|
#import <PushKit/PushKit.h>
|
|
|
#import "CallKit/CallKit.h"
|
|
#import "CallKit/CallKit.h"
|
|
|
-#import <netinet/in.h>
|
|
|
|
|
-#import <SystemConfiguration/SystemConfiguration.h>
|
|
|
|
|
|
|
+#import <AFNetworking/AFNetworkReachabilityManager.h>
|
|
|
#import "UserNetApi.h"
|
|
#import "UserNetApi.h"
|
|
|
#import "CryptoAES.h"
|
|
#import "CryptoAES.h"
|
|
|
#import "GWebSocket.h"
|
|
#import "GWebSocket.h"
|
|
@@ -38,11 +37,12 @@
|
|
|
@import JitsiMeetSDK;
|
|
@import JitsiMeetSDK;
|
|
|
|
|
|
|
|
@interface AppDelegate ()<UNUserNotificationCenterDelegate,PKPushRegistryDelegate,CXProviderDelegate>
|
|
@interface AppDelegate ()<UNUserNotificationCenterDelegate,PKPushRegistryDelegate,CXProviderDelegate>
|
|
|
|
|
+{
|
|
|
|
|
+ BOOL _isReachable;
|
|
|
|
|
+}
|
|
|
@property (nonatomic, strong) CXProvider *callProvider;
|
|
@property (nonatomic, strong) CXProvider *callProvider;
|
|
|
@property (nonatomic) NSUUID *uuid;
|
|
@property (nonatomic) NSUUID *uuid;
|
|
|
@property (nonatomic) NSDictionary *msg;
|
|
@property (nonatomic) NSDictionary *msg;
|
|
|
-@property (strong, nonatomic) NSTimer *timer;
|
|
|
|
|
-@property (nonatomic) NSInteger timerActCount;
|
|
|
|
|
@property (strong, nonatomic) NSString *bgMark;
|
|
@property (strong, nonatomic) NSString *bgMark;
|
|
|
|
|
|
|
|
@property (nonatomic) BOOL isTokenCleared;
|
|
@property (nonatomic) BOOL isTokenCleared;
|
|
@@ -80,8 +80,7 @@
|
|
|
[self checkLoginState:launchOptions];
|
|
[self checkLoginState:launchOptions];
|
|
|
[self registerPushright];
|
|
[self registerPushright];
|
|
|
[self setupCallProvider];
|
|
[self setupCallProvider];
|
|
|
- [self initAliyunOss];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ [self startNetworkReachability];
|
|
|
_isTokenCleared=YES;
|
|
_isTokenCleared=YES;
|
|
|
|
|
|
|
|
_floatWindow = [[FloatingWindow alloc] initWithFrame:self.window.bounds];
|
|
_floatWindow = [[FloatingWindow alloc] initWithFrame:self.window.bounds];
|
|
@@ -138,8 +137,6 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- [self startTimer];
|
|
|
|
|
- // 应用从后台返回前台时检查是否需要显示锁屏
|
|
|
|
|
}
|
|
}
|
|
|
-(void)applicationDidEnterBackground:(UIApplication *)application{
|
|
-(void)applicationDidEnterBackground:(UIApplication *)application{
|
|
|
NSLog(@"applicationDidEnterBackground");
|
|
NSLog(@"applicationDidEnterBackground");
|
|
@@ -164,7 +161,6 @@
|
|
|
self.shouldShowLock = YES;
|
|
self.shouldShowLock = YES;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- [self endTimer];
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ (instancetype)sharedInstance {
|
|
+ (instancetype)sharedInstance {
|
|
@@ -224,43 +220,26 @@
|
|
|
NSLog(@"Failed to get token, error: %@", error);
|
|
NSLog(@"Failed to get token, error: %@", error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-//阿里云oss:https://abtimoss.oss-ap-southeast-1.aliyuncs.com
|
|
|
|
|
-//AccessKey ID
|
|
|
|
|
-//LTAI5tNoRjDRMuvnKBcop3hL
|
|
|
|
|
-//AccessKey Secret
|
|
|
|
|
-//kUoR7zqLafRYpcz3vJk1JHTvkRaaSl
|
|
|
|
|
--(void)initAliyunOss{
|
|
|
|
|
-// [[OSSManager sharedManager] getOSSInfo];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
#pragma mark push token voip token
|
|
#pragma mark push token voip token
|
|
|
|
|
|
|
|
-(void)registerPushright{
|
|
-(void)registerPushright{
|
|
|
// 请求推送权限
|
|
// 请求推送权限
|
|
|
- if (@available(iOS 10.0, *)) {
|
|
|
|
|
- UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
|
- center.delegate = self; // 设置代理以处理通知相关事件
|
|
|
|
|
- [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvidesAppNotificationSettings) completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
|
|
|
- if (granted) {
|
|
|
|
|
- // 用户授权成功
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
- [[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- // 用户授权失败
|
|
|
|
|
- }
|
|
|
|
|
- }];
|
|
|
|
|
|
|
+ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
|
|
|
|
|
+ center.delegate = self; // 设置代理以处理通知相关事件
|
|
|
|
|
+ [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionProvidesAppNotificationSettings) completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
|
|
|
+ if (granted) {
|
|
|
|
|
+ // 用户授权成功
|
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
+ [[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
- // Fallback on earlier versions
|
|
|
|
|
- [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
|
|
|
|
|
- [[UIApplication sharedApplication] registerForRemoteNotifications];
|
|
|
|
|
|
|
+ // 用户授权失败
|
|
|
}
|
|
}
|
|
|
- PKPushRegistry *registry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
|
|
|
|
- registry.delegate = self;
|
|
|
|
|
- registry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
|
|
|
|
|
-
|
|
|
|
|
|
|
+ }];
|
|
|
|
|
+ PKPushRegistry *registry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
|
|
|
|
+ registry.delegate = self;
|
|
|
|
|
+ registry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -1045,99 +1024,25 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#pragma mark 检测网络状态
|
|
#pragma mark 检测网络状态
|
|
|
-
|
|
|
|
|
-#pragma mark 定时服务
|
|
|
|
|
--(void)startTimer{
|
|
|
|
|
- _timerActCount=0;
|
|
|
|
|
- if(self.timer){
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- self.timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(TimerAction) userInfo:nil repeats:YES];
|
|
|
|
|
- [self.timer setFireDate:[NSDate distantPast]];
|
|
|
|
|
- [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
--(void)endTimer{
|
|
|
|
|
- [self.timer invalidate];
|
|
|
|
|
- self.timer = nil;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
--(void)TimerAction{
|
|
|
|
|
- _timerActCount=_timerActCount+1;
|
|
|
|
|
- if(_timerActCount<3){
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- _timerActCount=0;
|
|
|
|
|
-// NSLog(@"111222222");
|
|
|
|
|
- if(![self isNetworkAvailable]){
|
|
|
|
|
- if(self.isLogin){
|
|
|
|
|
- [self onLogoutSucc];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- if(!self.isLogin){
|
|
|
|
|
- if (!_isTokenCleared) {
|
|
|
|
|
- [self clearVoipToken];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
--(BOOL)isNetworkAvailable{
|
|
|
|
|
- struct sockaddr_in zeroAddress;
|
|
|
|
|
- bzero(&zeroAddress, sizeof(zeroAddress));
|
|
|
|
|
- zeroAddress.sin_len = sizeof(zeroAddress);
|
|
|
|
|
- zeroAddress.sin_family = AF_INET;
|
|
|
|
|
- SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)&zeroAddress);
|
|
|
|
|
- if (reachability != NULL) {
|
|
|
|
|
- SCNetworkReachabilityFlags flags;
|
|
|
|
|
-
|
|
|
|
|
- if (SCNetworkReachabilityGetFlags(reachability, &flags)) {
|
|
|
|
|
- BOOL isReachable = ((flags & kSCNetworkFlagsReachable) != 0);
|
|
|
|
|
- BOOL needsConnection = ((flags & kSCNetworkFlagsConnectionRequired) != 0);
|
|
|
|
|
-
|
|
|
|
|
- BOOL isWWAN = (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0;
|
|
|
|
|
- if(isWWAN){
|
|
|
|
|
- NSLog(@"isWWAN:1----------");
|
|
|
|
|
- }
|
|
|
|
|
- else{
|
|
|
|
|
- NSLog(@"isWWAN:2----------");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+-(void)startNetworkReachability {
|
|
|
|
|
+ AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
|
|
|
|
|
+ __weak typeof(manager) weakManager = manager;
|
|
|
|
|
+ [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
|
|
|
|
|
+ BOOL isReachable = weakManager.isReachable;
|
|
|
|
|
+ self->_isReachable = isReachable;
|
|
|
|
|
+ NSLog(@"startNetworkReachability: %d", isReachable);
|
|
|
|
|
+ if (isReachable) {
|
|
|
|
|
|
|
|
- if ((isReachable && !needsConnection)) {
|
|
|
|
|
- // 网络是可用的,无需连接
|
|
|
|
|
-// NSLog(@"网络是可用的,无需连接");
|
|
|
|
|
- _NetReachable=YES;
|
|
|
|
|
- return YES;
|
|
|
|
|
- } else if ((isReachable && needsConnection)) {
|
|
|
|
|
- // 网络是可用的,需要连接(例如蜂窝数据或WiFi)
|
|
|
|
|
-// NSLog(@"网络是可用的,需要连接(例如蜂窝数据或WiFi)");
|
|
|
|
|
- _NetReachable=YES;
|
|
|
|
|
- return YES; // 根据实际需求决定是否返回YES或NO,这里仅为示例返回YES
|
|
|
|
|
- } else {
|
|
|
|
|
- // 网络不可用或无法确定状态
|
|
|
|
|
-// NSLog(@"网络不可用或无法确定状态");
|
|
|
|
|
- _NetReachable=NO;
|
|
|
|
|
- return NO;
|
|
|
|
|
- }
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- // 无法获取网络状态标志
|
|
|
|
|
-// NSLog(@"无法获取网络状态标志");
|
|
|
|
|
- _NetReachable=NO;
|
|
|
|
|
- return NO; // 根据实际需求处理错误情况
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- // 无法创建reachability对象,可能是因为参数错误等
|
|
|
|
|
-// NSLog(@"无法创建reachability对象,可能是因为参数错误等");
|
|
|
|
|
- _NetReachable=NO;
|
|
|
|
|
- return NO; // 根据实际需求处理错误情况
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+ [manager startMonitoring];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
--(BOOL)NetReachableState{
|
|
|
|
|
- return _NetReachable;
|
|
|
|
|
|
|
+- (BOOL)isReachable {
|
|
|
|
|
+ return _isReachable;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#pragma mark applock
|
|
#pragma mark applock
|
|
@@ -1160,27 +1065,5 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-- (void)continueAppInitializationAfterUnlock {
|
|
|
|
|
- // 这里可以添加解锁后需要执行的初始化代码
|
|
|
|
|
- NSLog(@"应用锁验证通过,继续应用初始化");
|
|
|
|
|
-
|
|
|
|
|
- // 例如:加载主界面数据、初始化服务等
|
|
|
|
|
- [self openMainController];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-- (void)continueWithSecurity{
|
|
|
|
|
- NSLog(@"-----安全登录成功-----");
|
|
|
|
|
- [self onLoginSucc];
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-- (void)clearApplicationBadge {
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
- [UIApplication sharedApplication].applicationIconBadgeNumber = 1; // 先设置为1
|
|
|
|
|
- [UIApplication sharedApplication].applicationIconBadgeNumber = 0; // 再设置为0
|
|
|
|
|
- // 这个技巧可以确保某些情况下角标被正确清除
|
|
|
|
|
- });
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
@end
|
|
@end
|