AppDelegate.mm 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. #import "AppDelegate.h"
  2. #import "JXXMMainVc.h"
  3. #import "JXMainViewController.h"
  4. #import "emojiViewController.h"
  5. #import "JXXMPP.h"
  6. #import "JXServer.h"
  7. #import "JXCommonService.h"
  8. #import "versionManage.h"
  9. #import "JXGroupViewController.h"
  10. #import "JXConstant.h"
  11. #import "loginVC.h"
  12. #import "BPush.h"
  13. #import "UMSocial.h"
  14. #import "UMSocialWechatHandler.h"
  15. #import "JXShareManage.h"
  16. //#import <AlipaySDK/AlipaySDK.h>
  17. #import <BaiduMapAPI_Map/BMKMapComponent.h>
  18. #if Meeting_Version
  19. #if !TARGET_IPHONE_SIMULATOR
  20. #import <JitsiMeet/JitsiMeet.h>
  21. #endif
  22. #endif
  23. #ifdef USE_GOOGLEMAP
  24. #import <GoogleMaps/GoogleMaps.h>
  25. #endif
  26. #import <AlipaySDK/AlipaySDK.h>
  27. #import "NumLockViewController.h"
  28. // iOS10 注册 APNs 所需头文件
  29. #ifdef NSFoundationVersionNumber_iOS_9_x_Max
  30. #import <UserNotifications/UserNotifications.h>
  31. #endif
  32. // 如果需要使用 idfa 功能所需要引入的头文件(可选)
  33. #import <AdSupport/AdSupport.h>
  34. #import <TencentOpenAPI/TencentOAuth.h>
  35. #import "TencentOpenAPI/QQApiInterface.h"
  36. #import "UMSocial.h"
  37. #import <Bugly/Bugly.h>
  38. //#define BUGLY_APP_ID @"d31e99928e"
  39. #define BUGLY_APP_ID @"a5a29670ad"
  40. #import "AvoidCrash.h"
  41. #import "XHLaunchAd.h"
  42. #import "webpageVC.h"
  43. #import "Network.h"
  44. #import "LaunchAdModel.h"
  45. #import "CYLaunchViewController.h"
  46. #import "CYWebAddPointVC.h"
  47. #import "JXCsHomeVc.h"
  48. #import "JXMainLoginVc.h"
  49. #import "JXLinksShareVC.h"
  50. #import "XMGMainViewController.h"
  51. #import "SimpleAudioPlayer.h"
  52. @interface AppDelegate () <BuglyDelegate>
  53. @property (nonatomic, strong) JXLinksShareVC *linksShareVC;
  54. @property (nonatomic,weak) NSString *linkName1;
  55. @property (nonatomic,weak) NSString *linkURL1;
  56. @property (nonatomic,weak) NSString *imgUrl1;
  57. @property (nonatomic,weak) NSString *linkName2;
  58. @property (nonatomic,weak) NSString *linkURL2;
  59. @property (nonatomic,weak) NSString *imgUrl2;
  60. @property (nonatomic,assign)int vcnum;
  61. @end
  62. @implementation AppDelegate
  63. @synthesize window,faceView,mainVc,config,jxServer;
  64. @synthesize jxConstant;
  65. #if TAR_IM
  66. #ifdef Meeting_Version
  67. @synthesize jxMeeting;
  68. #endif
  69. #endif
  70. static BMKMapManager* _baiduMapManager;
  71. - (void)dealloc
  72. {
  73. #if TAR_IM
  74. #ifdef Meeting_Version
  75. [jxMeeting stopMeeting];
  76. #endif
  77. #endif
  78. }
  79. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  80. {
  81. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  82. application.statusBarStyle = UIStatusBarStyleDefault;
  83. _navigation = [[JXNavigation alloc] init];
  84. if (@available(iOS 13.0, *)) {
  85. // window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
  86. }
  87. [AvoidCrash makeAllEffective];
  88. NSArray *noneSelClassStrings = @[
  89. @"NSNull",
  90. @"NSNumber",
  91. @"NSString",
  92. @"NSDictionary",
  93. @"NSArray"
  94. ];
  95. [AvoidCrash setupNoneSelClassStringsArr:noneSelClassStrings];
  96. [Bugly startWithAppId:BUGLY_APP_ID];
  97. // [g_default removeObjectForKey:@"refushMsgHistory"];
  98. // 网络监听
  99. [self networkStatusChange];
  100. _commonService = [[JXCommonService alloc] init];
  101. jxServer = [[JXServer alloc] init];
  102. config = [[versionManage alloc] init];
  103. jxConstant = [[JXConstant alloc]init];
  104. _didPushObj = [[JXDidPushObj alloc] init];
  105. _securityUtil = [[JXSecurityUtil alloc] init];
  106. _payServer = [[JXPayServer alloc] init];
  107. _loginServer = [[JXLoginServer alloc] init];
  108. #ifdef IS_MsgEncrypt
  109. _msgUtil = [[JXMsgUtil alloc] init];
  110. #endif
  111. #if TAR_IM
  112. #ifdef Meeting_Version
  113. jxMeeting = [[JXMeetingObject alloc] init];
  114. //[self startVoIPPush];
  115. #endif
  116. #endif
  117. // [NSThread sleepForTimeInterval:0.3];
  118. if ([[[NSUserDefaults standardUserDefaults] stringForKey:@"cylunch"] isEqualToString:@"1"]) {
  119. [self showLoginUI];
  120. }else {
  121. [self showPageUI];
  122. }
  123. // [self showLoginUI];
  124. // [self startPush:application didFinishLaunchingWithOptions:launchOptions];
  125. // 要使用百度地图,请先启动BaiduMapManager
  126. _baiduMapManager = [[BMKMapManager alloc]init];
  127. // 如果要关注网络及授权验证事件,请设定 generalDelegate参数
  128. NSString * identifier = [[NSBundle mainBundle] bundleIdentifier];
  129. BOOL ret = false;
  130. // if ([identifier isEqualToString:@"com.shiku.im.push"]) {//IM2
  131. // ret = [_baiduMapManager start:@"tVZRqzVYKwbwX7NytFnDWAUh4RbMnPDL" generalDelegate:nil];
  132. // }else if ([identifier isEqualToString:@"com.shiku.live.push1"]) {//直播
  133. // ret = [_baiduMapManager start:@"7YGiGTxFpa546GSxYt0RjVQ7yoz0oOdQ" generalDelegate:nil];
  134. // }else if ([identifier isEqualToString:@"com.shiku.coolim.push1"]) {//IM
  135. // ret = [_baiduMapManager start:@"YWCjFscGk7cv3RlEtaxoypzt0sipp6vw" generalDelegate:nil];
  136. // }
  137. // if ([identifier isEqualToString:@"com.kuxin.im"]) {//苹果版
  138. // ret = [_baiduMapManager start:@"LaxyefpZ3XY9mYVnewFFor5YKlDT9CCG" generalDelegate:nil];
  139. // }else if ([identifier isEqualToString:@"com.kuxin.im1"]) {//企业版
  140. // ret = [_baiduMapManager start:@"b0nfDKspEfGmT4u8GNwmOkm6Eh7V6nVg" generalDelegate:nil];
  141. // }
  142. ret = [_baiduMapManager start:@"7CUPsbXYIQbojuRLiSbQalzOU5n3VZP1" generalDelegate:nil];
  143. if (!ret)
  144. NSLog(@"BMKMapManager start faild!");
  145. //notice: 3.0.0 及以后版本注册可以这样写,也可以继续用之前的注册方式
  146. JPUSHRegisterEntity * entity = [[JPUSHRegisterEntity alloc] init];
  147. entity.types = JPAuthorizationOptionAlert|JPAuthorizationOptionBadge|JPAuthorizationOptionSound|JPAuthorizationOptionProvidesAppNotificationSettings;
  148. if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  149. // 可以添加自定义 categories
  150. // NSSet<UNNotificationCategory *> *categories for iOS10 or later
  151. // NSSet<UIUserNotificationCategory *> *categories for iOS8 and iOS9
  152. }
  153. [JPUSHService registerForRemoteNotificationConfig:entity delegate:self];
  154. // 获取 IDFA
  155. // 如需使用 IDFA 功能请添加此代码并在初始化方法的 advertisingIdentifier 参数中填写对应值
  156. NSString *advertisingId = [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
  157. // Required
  158. // init Push
  159. // notice: 2.1.5 版本的 SDK 新增的注册方法,改成可上报 IDFA,如果没有使用 IDFA 直接传 nil
  160. [JPUSHService setupWithOption:launchOptions appKey:JPUSHAPPKEY2
  161. channel:@"App Store"
  162. apsForProduction:YES
  163. advertisingIdentifier:advertisingId];
  164. [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
  165. if(resCode == 0){
  166. NSLog(@"registrationID获取成功:%@",registrationID);
  167. [g_default setObject:registrationID forKey:@"jPushRegistrationID"];
  168. }
  169. else{
  170. NSLog(@"registrationID获取失败,code:%d",resCode);
  171. }
  172. }];
  173. //谷歌地图
  174. #ifdef USE_GOOGLEMAP
  175. [GMSServices provideAPIKey:@"AIzaSyABu5gPAX0xzT1uw-W2q8XKQxxnEBNXSK8"];
  176. #endif
  177. // if (![g_default boolForKey:kUseGoogleMap]) {
  178. // [g_default setBool:NO forKey:kUseGoogleMap];
  179. // } 5edaacbe978eea085d11d331
  180. // 设置友盟AppKey
  181. [UMSocialData setAppKey:@"5edaacbe978eea085d11d331"];
  182. // [WXApi registerApp:MXWechatAPPID enableMTA:NO];
  183. [UMSocialWechatHandler setWXAppId:MXWechatAPPID appSecret:MXWechatAPPSecret url:@"https://apps.apple.com/cn/app/%E8%81%8A%E5%95%B5-%E4%B8%8E%E6%9C%8B%E5%8F%8B%E4%B8%80%E8%B5%B7%E7%95%85%E8%81%8A/id1463401862"];
  184. p://www.yshow.net"];
  185. //设置分享到QQ空间的应用Id,和分享url 链接
  186. //[UMSocialQQHandler defaultManager];
  187. //设置支持没有客户端情况下使用SSO授权
  188. //[UMSocialQQHandler setSupportWebView:YES];
  189. // 设置QQ登录appId
  190. self.QQ_LOGIN_APPID = @"1110165201";
  191. [self registerAPN];
  192. [self setUserAgent];
  193. NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  194. // [g_notify postNotificationName:kDidReceiveRemoteNotification object:pushNotificationKey];
  195. [g_default setObject:pushNotificationKey forKey:kDidReceiveRemoteDic];
  196. [g_default synchronize];
  197. // 实时更新缓存
  198. // [self setSDWebImageHeader];
  199. return YES;
  200. }
  201. // 能实时更新缓存
  202. - (void)setSDWebImageHeader {
  203. SDWebImageDownloader *imgDownloader = SDWebImageManager.sharedManager.imageDownloader;
  204. imgDownloader.headersFilter = ^NSDictionary *(NSURL *url, NSDictionary *headers) {
  205. NSFileManager *fm = [[NSFileManager alloc] init];
  206. NSString *imgKey = [SDWebImageManager.sharedManager cacheKeyForURL:url];
  207. NSString *imgPath = [SDWebImageManager.sharedManager.imageCache defaultCachePathForKey:imgKey];
  208. NSDictionary *fileAttr = [fm attributesOfItemAtPath:imgPath error:nil];
  209. NSMutableDictionary *mutableHeaders = [headers mutableCopy];
  210. NSDate *lastModifiedDate = nil;
  211. if (fileAttr.count > 0) {
  212. if (fileAttr.count > 0) {
  213. lastModifiedDate = (NSDate *)fileAttr[NSFileModificationDate];
  214. }
  215. }
  216. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  217. formatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
  218. formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
  219. formatter.dateFormat = @"EEE, dd MMM yyyy HH:mm:ss z";
  220. NSString *lastModifiedStr = [formatter stringFromDate:lastModifiedDate];
  221. lastModifiedStr = lastModifiedStr.length > 0 ? lastModifiedStr : @"";
  222. [mutableHeaders setValue:lastModifiedStr forKey:@"If-Modified-Since"];
  223. return mutableHeaders;
  224. };
  225. }
  226. - (void)showPageUI {
  227. CYLaunchViewController *lunchVC = [[CYLaunchViewController alloc] init];
  228. g_navigation.rootViewController = lunchVC;
  229. }
  230. - (NSString *)getNowTimeTimestamp3{
  231. NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
  232. NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)([datenow timeIntervalSince1970])];
  233. return timeSp;
  234. }
  235. - (void)setupLunchADUrl:(NSString *)url link:(NSString *)link {
  236. BOOL sameDateFlag = NO;
  237. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  238. [formatter setDateFormat:@"yyyy-MM-dd"];
  239. NSString *nowday = [formatter stringFromDate:[NSDate date]];
  240. NSString *saveDay = [[NSUserDefaults standardUserDefaults] objectForKey:@"versionUpdateKey"];
  241. if (saveDay == nil) {
  242. saveDay = @"";
  243. }
  244. if (![saveDay isEqualToString:nowday]) { //假如不是同一天,更新存储的日期,并且把flag置为YES
  245. [[NSUserDefaults standardUserDefaults] setObject:nowday forKey:@"versionUpdateKey"];
  246. sameDateFlag = YES;
  247. }
  248. if (sameDateFlag) {
  249. return;
  250. }
  251. int x = -1;
  252. if ([url.lowercaseString containsString:@".mp4"]) {
  253. x = 1;
  254. } else {
  255. x = 0;
  256. }
  257. if (x==0) {
  258. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  259. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchImage];
  260. //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  261. //2.设为2即表示:启动页将停留2s等待服务器返回广告数据,2s内等到广告数据,将正常显示广告,否则将不显示
  262. //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  263. //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  264. [XHLaunchAd setWaitDataDuration:2];
  265. //广告数据请求
  266. //配置广告数据
  267. XHLaunchImageAdConfiguration *imageAdconfiguration = [XHLaunchImageAdConfiguration new];
  268. //广告停留时间
  269. imageAdconfiguration.duration = 5;
  270. //广告frame
  271. imageAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  272. //广告图片URLString/或本地图片名(.jpg/.gif请带上后缀)
  273. imageAdconfiguration.imageNameOrURLString = url;
  274. //设置GIF动图是否只循环播放一次(仅对动图设置有效)
  275. imageAdconfiguration.GIFImageCycleOnce = NO;
  276. //缓存机制(仅对网络图片有效)
  277. //为告展示效果更好,可设置为XHLaunchAdImageCacheInBackground,先缓存,下次显示
  278. imageAdconfiguration.imageOption = XHLaunchAdImageDefault;
  279. //图片填充模式
  280. imageAdconfiguration.contentMode = UIViewContentModeScaleToFill;
  281. //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  282. imageAdconfiguration.openModel = link;
  283. //广告显示完成动画
  284. imageAdconfiguration.showFinishAnimate =ShowFinishAnimateLite;
  285. //广告显示完成动画时间
  286. imageAdconfiguration.showFinishAnimateTime = 0.8;
  287. //跳过按钮类型
  288. imageAdconfiguration.skipButtonType = SkipTypeTimeText;
  289. //后台返回时,是否显示广告
  290. imageAdconfiguration.showEnterForeground = NO;
  291. //设置要添加的自定义视图(可选)
  292. //imageAdconfiguration.subViews = ...
  293. //显示开屏广告
  294. [XHLaunchAd imageAdWithImageAdConfiguration:imageAdconfiguration delegate:self];
  295. }else {
  296. //设置你工程的启动页使用的是:LaunchImage 还是 LaunchScreen.storyboard(不设置默认:LaunchImage)
  297. [XHLaunchAd setLaunchSourceType:SourceTypeLaunchImage];
  298. //1.因为数据请求是异步的,请在数据请求前,调用下面方法配置数据等待时间.
  299. //2.设为2即表示:启动页将停留2s等待服务器返回广告数据,2s内等到广告数据,将正常显示广告,否则将不显示
  300. //3.数据获取成功,配置广告数据后,自动结束等待,显示广告
  301. //注意:请求广告数据前,必须设置此属性,否则会先进入window的的根控制器
  302. [XHLaunchAd setWaitDataDuration:2];
  303. //广告数据请求
  304. //配置广告数据
  305. XHLaunchVideoAdConfiguration *videoAdconfiguration = [XHLaunchVideoAdConfiguration new];
  306. //广告停留时间
  307. videoAdconfiguration.duration = 10;
  308. //广告frame
  309. videoAdconfiguration.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
  310. //广告视频URLString/或本地视频名(请带上后缀)
  311. //注意:视频广告只支持先缓存,下次显示(看效果请二次运行)
  312. videoAdconfiguration.videoNameOrURLString = url;
  313. //是否关闭音频
  314. videoAdconfiguration.muted = NO;
  315. //视频填充模式
  316. videoAdconfiguration.videoGravity = AVLayerVideoGravityResizeAspectFill;
  317. //是否只循环播放一次
  318. videoAdconfiguration.videoCycleOnce = YES;
  319. //广告点击打开页面参数(openModel可为NSString,模型,字典等任意类型)
  320. videoAdconfiguration.openModel = link;
  321. //广告显示完成动画
  322. videoAdconfiguration.showFinishAnimate =ShowFinishAnimateFadein;
  323. //广告显示完成动画时间
  324. videoAdconfiguration.showFinishAnimateTime = 0.8;
  325. //后台返回时,是否显示广告
  326. videoAdconfiguration.showEnterForeground = NO;
  327. //跳过按钮类型
  328. videoAdconfiguration.skipButtonType = SkipTypeTimeText;
  329. //设置要添加的自定义视图(可选)
  330. //videoAdconfiguration.subViews = ...
  331. [XHLaunchAd videoAdWithVideoAdConfiguration:videoAdconfiguration delegate:self];
  332. }
  333. }
  334. - (void)setUserAgent {
  335. UIWebView *webView = [[UIWebView alloc] init];
  336. NSString *originUA = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
  337. NSString *newUA = [NSString stringWithFormat:@"%@ %@",originUA,@"app-shikuimapp"];
  338. NSDictionary *dictionary = @{@"UserAgent":newUA};
  339. [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  340. }
  341. - (void)registerAPN{
  342. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
  343. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  344. }
  345. -(UIView *)subWindow
  346. {
  347. if (!_subWindow) {
  348. _subWindow = [[UIView alloc] initWithFrame:CGRectMake(100,200,80,80)];
  349. // _subWindow.windowLevel = UIWindowLevelAlert +1;
  350. // [_subWindow makeKeyAndVisible]; //关键语句,显示窗口
  351. [g_window addSubview:_subWindow];
  352. }
  353. return _subWindow;
  354. }
  355. /**
  356. *关闭悬浮的窗口
  357. */
  358. - (void)resignWindow
  359. {
  360. // [_subWindow resignKeyWindow];
  361. [_subWindow removeFromSuperview];
  362. _subWindow = nil ;
  363. }
  364. -(void)showLoginUI{
  365. //修改的
  366. //NSString *path = [[NSBundle mainBundle] pathForResource:@"movie.mp4" ofType:nil];
  367. JXMainLoginVc* vc = [JXMainLoginVc alloc];
  368. vc.isAutoLogin = YES;
  369. vc.isSwitchUser= NO;
  370. vc = [vc init];
  371. // vc.movieURL = [NSURL fileURLWithPath:path];
  372. g_navigation.rootViewController = vc;
  373. /*
  374. loginVC* vc = [loginVC alloc];
  375. vc.isAutoLogin = YES;
  376. vc.isSwitchUser= NO;
  377. vc = [vc init];
  378. g_navigation.rootViewController = vc;
  379. */
  380. return;
  381. [self.window addSubview:vc.view];
  382. self.window.rootViewController = vc;
  383. [self.window makeKeyAndVisible];
  384. //
  385. // _navigation = [[JXNavigation alloc] init];
  386. // [g_navigation.subViews removeAllObjects];
  387. // [g_navigation pushViewController:vc];
  388. }
  389. -(void)showMainUI{
  390. // if(mainVc==nil){
  391. // mainVc=[[JXMainViewController alloc]init];
  392. // XMGTabarVC *tabbarVc=[[XMGTabarVC alloc]init];
  393. // }
  394. g_navigation.rootViewController = [JXCsHomeVc new] ;// ;
  395. int heightHome = 228;
  396. if (THE_DEVICE_HAVE_HEAD) {
  397. heightHome = 225+JX_SCREEN_BOTTOM_SAFE_AREA;
  398. }
  399. faceView = [[emojiViewController alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT-heightHome-JX_SCREEN_TOP, JX_SCREEN_WIDTH, heightHome)];
  400. int height = 218;
  401. if (THE_DEVICE_HAVE_HEAD) {
  402. height = 263;
  403. }
  404. int height2 = 164;
  405. if (THE_DEVICE_HAVE_HEAD) {
  406. height2 = 164;
  407. }
  408. _faceView2 = [[emojiViewController alloc]initWithFrame:CGRectMake(0, JX_SCREEN_HEIGHT-height2-JX_SCREEN_TOP, JX_SCREEN_WIDTH, height)];
  409. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  410. if (str.length > 0) {
  411. [self showDeviceLock];
  412. }
  413. [g_notify postNotificationName:kLaunchAdShowFinishNotifaction object:nil];
  414. }
  415. - (void)applicationDidEnterBackground:(UIApplication *)application
  416. {
  417. // 进入后台
  418. [g_notify postNotificationName:kApplicationDidEnterBackground object:nil];
  419. [g_notify postNotificationName:kAllVideoPlayerStopNotifaction object:nil userInfo:nil];
  420. [g_notify postNotificationName:kAllAudioPlayerStopNotifaction object:nil userInfo:nil];
  421. NSLog(@"XMPP ---- Appdelegate");
  422. if (g_server.isLogin) {
  423. [g_server userChangeMsgNum:[UIApplication sharedApplication].applicationIconBadgeNumber toView:self];
  424. }
  425. #if TAR_IM
  426. #ifdef Meeting_Version
  427. [jxMeeting meetingDidEnterBackground:application];
  428. if (!g_meeting.isMeeting) {
  429. if (g_server.isLogin) {
  430. [g_server outTime:nil];
  431. }
  432. g_xmpp.isCloseStream = YES;
  433. g_xmpp.isReconnect = NO;
  434. // [g_xmpp logout];
  435. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  436. if (str.length > 0) {
  437. [self showDeviceLock];
  438. }
  439. }
  440. UIApplication* app = [UIApplication sharedApplication];
  441. __block UIBackgroundTaskIdentifier bgTask;
  442. bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
  443. dispatch_async(dispatch_get_main_queue(), ^{
  444. if (bgTask != UIBackgroundTaskInvalid)
  445. {
  446. bgTask = UIBackgroundTaskInvalid;
  447. }
  448. });
  449. }];
  450. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  451. dispatch_async(dispatch_get_main_queue(), ^{
  452. if (bgTask != UIBackgroundTaskInvalid)
  453. {
  454. bgTask = UIBackgroundTaskInvalid;
  455. }
  456. });
  457. });
  458. #else
  459. if (g_server.isLogin) {
  460. [g_server outTime:nil];
  461. }
  462. g_xmpp.isCloseStream = YES;
  463. g_xmpp.isReconnect = NO;
  464. // [g_xmpp logout];
  465. NSString *str = [g_default stringForKey:kDeviceLockPassWord];
  466. if (str.length > 0) {
  467. [self showDeviceLock];
  468. }
  469. UIApplication* app = [UIApplication sharedApplication];
  470. __block UIBackgroundTaskIdentifier bgTask;
  471. bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
  472. dispatch_async(dispatch_get_main_queue(), ^{
  473. if (bgTask != UIBackgroundTaskInvalid)
  474. {
  475. bgTask = UIBackgroundTaskInvalid;
  476. }
  477. });
  478. }];
  479. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  480. dispatch_async(dispatch_get_main_queue(), ^{
  481. if (bgTask != UIBackgroundTaskInvalid)
  482. {
  483. bgTask = UIBackgroundTaskInvalid;
  484. }
  485. });
  486. });
  487. #endif
  488. #endif
  489. NSLog(@"程序后台");
  490. }
  491. - (void)showDeviceLock {
  492. if (!self.isShowDeviceLock) {
  493. [g_window endEditing:YES];
  494. self.isShowDeviceLock = YES;
  495. _numLockVC = [[NumLockViewController alloc]init];
  496. _numLockVC.isClose = NO;
  497. [g_window addSubview:_numLockVC.view];
  498. }
  499. }
  500. - (void)applicationWillEnterForeground:(UIApplication *)application
  501. {
  502. [config showDisableUse];
  503. [g_notify postNotificationName:kApplicationWillEnterForeground object:nil];
  504. // NSLog(@"applicationWillEnterForeground");
  505. if(g_server.isLogin){
  506. // NSLog(@"login");
  507. [[JXXMPP sharedInstance] login];
  508. #if TAR_IM
  509. #ifdef Meeting_Version
  510. [jxMeeting meetingWillEnterForeground:application];
  511. #endif
  512. #endif
  513. }
  514. // 清除过期聊天记录
  515. [[JXUserObject sharedInstance] deleteUserChatRecordTimeOutMsg];
  516. }
  517. //- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
  518. // NSLog(@"OpenURL:%@",url);
  519. // //如果极简开发包不可用,会跳转支付宝钱包进行支付,需要将支付宝钱包的支付结果回传给开发包
  520. //// if ([url.host isEqualToString:@"safepay"]) {
  521. //// [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
  522. //// //【由于在跳转支付宝客户端支付的过程中,商户app在后台很可能被系统kill了,所以pay接口的callback就会失效,请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】
  523. //// NSLog(@"result = %@",resultDic);
  524. //// }];
  525. //// }
  526. //// if ([url.host isEqualToString:@"platformapi"]){//支付宝钱包快登授权返回authCode
  527. ////
  528. //// [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic) {
  529. //// //【由于在跳转支付宝客户端支付的过程中,商户app在后台很可能被系统kill了,所以pay接口的callback就会失效,请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】
  530. //// NSLog(@"result = %@",resultDic);
  531. //// }];
  532. //// }
  533. //
  534. // return YES;
  535. //}
  536. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  537. {
  538. // QQ
  539. if (YES == [TencentOAuth CanHandleOpenURL:url]) {
  540. return [TencentOAuth HandleOpenURL:url];
  541. }
  542. [[JXShareManage sharedManager] handleOpenURL:url delegate:nil];
  543. return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  544. }
  545. - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  546. {
  547. //#if Meeting_Version
  548. //#if !TARGET_IPHONE_SIMULATOR
  549. // [JitsiMeetView application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  550. //#endif
  551. //#endif
  552. [[JXShareManage sharedManager] handleOpenURL:url delegate:nil];
  553. //跳转支付宝钱包进行支付,处理支付结果
  554. if ([url.host isEqualToString:@"safepay"]) {
  555. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:nil];
  556. }else {
  557. if (YES == [TencentOAuth CanHandleOpenURL:url])
  558. {
  559. return [TencentOAuth HandleOpenURL:url];
  560. }else{
  561. return [UMSocialSnsService handleOpenURL:url wxApiDelegate:nil];
  562. }
  563. }
  564. return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  565. }
  566. // NOTE: 9.0以后使用新API接口
  567. - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
  568. {
  569. #if Meeting_Version
  570. #if !TARGET_IPHONE_SIMULATOR
  571. // [JitsiMeetView application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
  572. [[JitsiMeet sharedInstance] application:app openURL:url options:options];
  573. #endif
  574. #endif
  575. if ([url.host isEqualToString:@"safepay"]) {
  576. [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:nil];
  577. // 授权跳转支付宝钱包进行支付,处理支付结果
  578. [[AlipaySDK defaultService] processAuth_V2Result:url standbyCallback:^(NSDictionary *resultDic) {
  579. NSLog(@"result = %@",resultDic);
  580. // 解析 auth code
  581. NSString *result = resultDic[@"result"];
  582. NSString *authCode = nil;
  583. if (result.length>0) {
  584. NSArray *resultArr = [result componentsSeparatedByString:@"&"];
  585. for (NSString *subResult in resultArr) {
  586. if (subResult.length > 10 && [subResult hasPrefix:@"auth_code="]) {
  587. authCode = [subResult substringFromIndex:10];
  588. break;
  589. }
  590. }
  591. }
  592. NSLog(@"授权结果 authCode = %@", authCode?:@"");
  593. }];
  594. }
  595. // QQ登录回调
  596. else if ([url.host isEqualToString:@"qzapp"]) {
  597. if (YES == [TencentOAuth CanHandleOpenURL:url])
  598. {
  599. return [TencentOAuth HandleOpenURL:url];
  600. }
  601. }
  602. [[JXShareManage sharedManager] handleOpenURL:url delegate:nil];
  603. return [WXApi handleOpenURL:url delegate:[WXApiManager sharedManager]];
  604. }
  605. #if Meeting_Version
  606. #if !TARGET_IPHONE_SIMULATOR
  607. - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler{
  608. return [[JitsiMeet sharedInstance] application:application
  609. continueUserActivity:userActivity
  610. restorationHandler:restorationHandler];
  611. }
  612. #endif
  613. #endif
  614. - (void)applicationDidBecomeActive:(UIApplication *)application
  615. {
  616. // 进入活跃
  617. [g_notify postNotificationName:kApplicationDidBecomeActive object:nil];
  618. [UMSocialSnsService applicationDidBecomeActive];
  619. // if(g_server.isLogin && g_xmpp.isLogined != login_status_yes)
  620. // [[JXXMPP sharedInstance] login];
  621. }
  622. - (void)applicationWillResignActive:(UIApplication *)application {
  623. if (g_server.isLogin) {
  624. [g_server userChangeMsgNum:[UIApplication sharedApplication].applicationIconBadgeNumber toView:self];
  625. }
  626. // if(g_server.isLogin) {
  627. // [g_server outTime:nil];
  628. // g_xmpp.isCloseStream = YES;
  629. // g_xmpp.isReconnect = NO;
  630. // [g_xmpp logout];
  631. // }
  632. }
  633. - (void) showAlert: (NSString *) message
  634. {
  635. UIAlertView *av = [[UIAlertView alloc] initWithTitle:APP_NAME message:message delegate:self cancelButtonTitle:Localized(@"JX_Confirm") otherButtonTitles:nil, nil];
  636. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  637. [av show];
  638. [g_navigation resetVCFrame];
  639. });
  640. // [av release];
  641. }
  642. - (UIAlertView *) showAlert: (NSString *) message delegate:(id)delegate
  643. {
  644. UIAlertView *av = [[UIAlertView alloc] initWithTitle:APP_NAME message:message delegate:delegate cancelButtonTitle:Localized(@"JX_Cencal") otherButtonTitles:Localized(@"JX_Confirm"), nil];
  645. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  646. [av show];
  647. [g_navigation resetVCFrame];
  648. });
  649. return av;
  650. }
  651. - (UIAlertView *) showAlert: (NSString *) message delegate:(id)delegate tag:(NSUInteger)tag onlyConfirm:(BOOL)onlyConfirm
  652. {
  653. UIAlertView *av;
  654. if (onlyConfirm)
  655. av = [[UIAlertView alloc] initWithTitle:APP_NAME message:message delegate:delegate cancelButtonTitle:Localized(@"JX_Confirm") otherButtonTitles:nil];
  656. else
  657. av = [[UIAlertView alloc] initWithTitle:APP_NAME message:message delegate:delegate cancelButtonTitle:Localized(@"JX_Cencal") otherButtonTitles:Localized(@"JX_Confirm"), nil];
  658. av.tag = tag;
  659. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  660. [av show];
  661. [g_navigation resetVCFrame];
  662. });
  663. return av;
  664. }
  665. //- (void)resetVCFrame {
  666. // UIViewController *vc = g_navigation.subViews.lastObject;
  667. // if (vc == g_navigation.lastVC) {
  668. // return;
  669. // }
  670. // // 页面复位
  671. // vc.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, vc.view.frame.size.height);
  672. // g_navigation.lastVC.view.frame = CGRectMake(-JX_SCREEN_WIDTH, 0, g_navigation.lastVC.view.frame.size.width, g_navigation.lastVC.view.frame.size.height);
  673. // [g_navigation.lastVC.view removeFromSuperview];
  674. // vc.view.userInteractionEnabled = YES;
  675. // g_navigation.lastVC.view.userInteractionEnabled = YES;
  676. //}
  677. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
  678. #if TAR_IM
  679. #ifdef Meeting_Version
  680. // [jxMeeting doNotify:notification];
  681. #endif
  682. #endif
  683. // NSLog(@"推送:接收本地通知啦!!!");
  684. // [BPush showLocalNotificationAtFront:notification identifierKey:nil];
  685. }
  686. - (void)applicationProtectedDataWillBecomeUnavailable:(UIApplication *)application {
  687. [SimpleAudioPlayer stopAllPlayers];
  688. }
  689. - (void)applicationProtectedDataDidBecomeAvailable:(UIApplication *)application {
  690. [SimpleAudioPlayer stopAllPlayers];
  691. }
  692. - (void)applicationWillTerminate:(UIApplication *)application {
  693. NSLog(@"程序杀死");
  694. [g_server userChangeMsgNum:[UIApplication sharedApplication].applicationIconBadgeNumber toView:self];
  695. [g_server outTime:nil];
  696. g_xmpp.isCloseStream = YES;
  697. g_xmpp.isReconnect = NO;
  698. [g_xmpp logout];
  699. #if TAR_IM
  700. #ifdef Meeting_Version
  701. [jxMeeting doTerminate];
  702. [self endCall];
  703. #endif
  704. #endif
  705. }
  706. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
  707. #if TAR_IM
  708. #ifdef Meeting_Version
  709. [jxMeeting clearMemory];
  710. #endif
  711. #endif
  712. }
  713. -(void)startPush:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
  714. // iOS8 下需要使用新的 API
  715. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
  716. UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
  717. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
  718. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  719. }else {
  720. UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
  721. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
  722. }
  723. // 在 App 启动时注册百度云推送服务,需要提供 Apikey
  724. NSString * identifier = [[NSBundle mainBundle] bundleIdentifier];
  725. //app.jixincc.vip com.shiku.im.push
  726. if ([identifier isEqualToString:@"app.jixincc.vip"]) {
  727. [BPush registerChannel:launchOptions apiKey:@"YWCjFscGk7cv3RlEtaxoypzt0sipp6vw" pushMode: BPushModeProduction withFirstAction:nil withSecondAction:nil withCategory:nil useBehaviorTextInput:YES isDebug:NO];
  728. }else{
  729. [BPush registerChannel:launchOptions apiKey:@"7LlWDe0AZGKILS4Tq5cMNMum" pushMode: BPushModeProduction withFirstAction:nil withSecondAction:nil withCategory:nil useBehaviorTextInput:YES isDebug:NO];
  730. }
  731. //
  732. // App 是用户点击推送消息启动
  733. NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  734. if (userInfo) {
  735. // NSLog(@"从消息启动:%@",userInfo);
  736. [BPush handleNotification:userInfo];
  737. }
  738. #if TARGET_IPHONE_SIMULATOR
  739. Byte dt[32] = {0xc6, 0x1e, 0x5a, 0x13, 0x2d, 0x04, 0x83, 0x82, 0x12, 0x4c, 0x26, 0xcd, 0x0c, 0x16, 0xf6, 0x7c, 0x74, 0x78, 0xb3, 0x5f, 0x6b, 0x37, 0x0a, 0x42, 0x4f, 0xe7, 0x97, 0xdc, 0x9f, 0x3a, 0x54, 0x10};
  740. [self application:application didRegisterForRemoteNotificationsWithDeviceToken:[NSData dataWithBytes:dt length:32]];
  741. #endif
  742. //角标清0
  743. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  744. }
  745. //// 此方法是 用户点击了通知,应用在前台 或者开启后台并且应用在后台 时调起
  746. //- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
  747. //{
  748. // completionHandler(UIBackgroundFetchResultNewData);
  749. // // 打印到日志 textView 中
  750. //// NSLog(@"********** iOS7.0之后 background **********");
  751. // // 应用在前台 或者后台开启状态下,不跳转页面,让用户选择。
  752. // if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) {
  753. //// NSLog(@"acitve or background");
  754. //// [self showAlert:userInfo[@"aps"][@"alert"]];
  755. // }
  756. // else//杀死状态下,直接跳转到跳转页面。
  757. // {
  758. // }
  759. //}
  760. // 在 iOS8 系统中,还需要添加这个方法。通过新的 API 注册推送服务
  761. - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
  762. {
  763. [application registerForRemoteNotifications];
  764. }
  765. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
  766. {
  767. NSLog(@"test:%@",deviceToken);
  768. // NSString *token = [NSString stringWithFormat:@"%@",deviceToken];
  769. NSString * token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""];
  770. //apnsToken 需要提交给服务器
  771. [g_default setObject:token forKey:@"apnsToken"];
  772. [BPush registerDeviceToken:deviceToken];
  773. [BPush bindChannelWithCompleteHandler:^(id result, NSError *error) {
  774. // 需要在绑定成功后进行 settag listtag deletetag unbind 操作否则会失败
  775. if (result) {
  776. [BPush setTag:@"Mytag" withCompleteHandler:^(id result, NSError *error) {
  777. if (result) {
  778. NSLog(@"设置tag成功");
  779. }
  780. }];
  781. }
  782. }];
  783. /// 极光推送 - 注册 DeviceToken
  784. [JPUSHService registerDeviceToken:deviceToken];
  785. }
  786. // 当 DeviceToken 获取失败时,系统会回调此方法
  787. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
  788. {
  789. NSLog(@"DeviceToken 获取失败,原因:%@",error);
  790. }
  791. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  792. {
  793. // App 收到推送的通知
  794. [BPush handleNotification:userInfo];
  795. // Required, For systems with less than or equal to iOS 6
  796. [JPUSHService handleRemoteNotification:userInfo];
  797. [g_default setObject:userInfo forKey:kDidReceiveRemoteDic];
  798. [g_default synchronize];
  799. // [g_notify postNotificationName:kDidReceiveRemoteNotification object:userInfo];
  800. // NSLog(@"********** ios7.0之前 **********");
  801. // 应用在前台 或者后台开启状态下,不跳转页面,让用户选择。
  802. if (application.applicationState == UIApplicationStateActive || application.applicationState == UIApplicationStateBackground) {
  803. // NSLog(@"acitve or background");
  804. // [self showAlert:userInfo[@"aps"][@"alert"]];
  805. }
  806. else//杀死状态下,直接跳转到跳转页面。
  807. {
  808. }
  809. }
  810. #pragma mark- JPUSHRegisterDelegate
  811. // iOS 12 Support
  812. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center openSettingsForNotification:(UNNotification *)notification{
  813. NSDictionary * userInfo = notification.request.content.userInfo;
  814. if (notification && [notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  815. //从通知界面直接进入应用 应用处于前台收到推送的时候转成本地通知 ===========================
  816. UILocalNotification *notification = [[UILocalNotification alloc] init];
  817. NSDictionary *dic = userInfo[@"aps"];
  818. notification.alertTitle =dic[@"alert"];
  819. // notification.alertBody =@"aaaaaa";
  820. notification.userInfo = userInfo;
  821. [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
  822. }else{
  823. // NSLog(@"++++++++++++++++++++++++++");
  824. /// 应用处于前台收到本地通知不会出现在通知中心 借用极光推送的方法将本地通知添加到通知栏 ==============================
  825. }
  826. }
  827. // iOS 10 Support 在前台推送时候的方法
  828. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
  829. // Required
  830. NSDictionary * userInfo = notification.request.content.userInfo;
  831. [g_default setObject:userInfo forKey:kDidReceiveRemoteDic];
  832. [g_default synchronize];
  833. if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  834. [JPUSHService handleRemoteNotification:userInfo];
  835. }
  836. completionHandler(UNNotificationPresentationOptionAlert); // 需要执行这个方法,选择是否提醒用户,有 Badge、Sound、Alert 三种类型可以选择设置
  837. }
  838. // iOS 10 Support // 点击通知调研的方法--前台后台抖一样调用这个方法
  839. - (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  840. // Required
  841. NSDictionary * userInfo = response.notification.request.content.userInfo;
  842. [g_default setObject:userInfo forKey:kDidReceiveRemoteDic];
  843. [g_default synchronize];
  844. [SimpleAudioPlayer stopAllPlayers];
  845. if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
  846. [JPUSHService handleRemoteNotification:userInfo];
  847. }
  848. completionHandler(); // 系统要求执行这个方法
  849. }
  850. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  851. [g_default setObject:userInfo forKey:kDidReceiveRemoteDic];
  852. [g_default synchronize];
  853. NSDictionary *dict=userInfo;
  854. NSLog(@"%@",dict); //接受推送在后台
  855. // Required, iOS 7 Support
  856. [JPUSHService handleRemoteNotification:userInfo];
  857. completionHandler(UIBackgroundFetchResultNewData);
  858. }
  859. // 监听网络状态
  860. - (void)networkStatusChange {
  861. AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
  862. [manager startMonitoring];
  863. [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  864. if (status != AFNetworkReachabilityStatusNotReachable) {
  865. if (g_server.isLogin) {
  866. if (g_xmpp.isLogined != login_status_yes) {
  867. [[JXXMPP sharedInstance] logout];
  868. [[JXXMPP sharedInstance] login];
  869. }
  870. }
  871. }else {
  872. [g_default removeObjectForKey:@"refushMsgHistoryxxx"];
  873. [g_xmpp.reconnectTimer invalidate];
  874. g_xmpp.reconnectTimer = nil;
  875. g_xmpp.isReconnect = NO;
  876. [[JXXMPP sharedInstance] logout];
  877. [JXMyTools showTipView:Localized(@"JX_NetWorkError")];
  878. }
  879. }];
  880. }
  881. #if TAR_IM
  882. #ifdef Meeting_Version
  883. -(void)startVoIPPush{
  884. NSString * identifier = [[NSBundle mainBundle] bundleIdentifier];
  885. NSLog(@"callkit - start"); // com.shiku.im.push app.jixincc.vip
  886. if ([identifier isEqualToString:@"app.jixincc.vip"] && [[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
  887. PKPushRegistry * pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
  888. pushRegistry.delegate = self;
  889. pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
  890. }else{
  891. [g_default removeObjectForKey:@"voipToken"];
  892. }
  893. }
  894. #pragma mark - PKPushRegistryDelegate
  895. -(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type{
  896. if ([credentials.token length] == 0) {
  897. NSLog(@"voip token NULL");
  898. return;
  899. }
  900. NSString * voipToken = [[[[credentials.token description] stringByReplacingOccurrencesOfString:@"<" withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""];
  901. //voipToken 需要提交给服务器
  902. [g_default setObject:voipToken forKey:@"voipToken"];
  903. NSLog(@"voipToken:%@",voipToken);
  904. }
  905. -(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type{
  906. NSLog(@"callkit - didreceive");
  907. if (type != PKPushTypeVoIP) {
  908. return;
  909. }
  910. NSString * fromUserName = payload.dictionaryPayload[@"fromUserName"];
  911. int messageType = [[NSString stringWithFormat:@"%@",payload.dictionaryPayload[@"messageType"]] intValue];
  912. BOOL isCallKit = messageType == kWCMessageTypeAudioChatAsk ? YES : NO;
  913. BOOL isAudio = (messageType == kWCMessageTypeAudioChatAsk || messageType == kWCMessageTypeAudioMeetingInvite) ? YES : NO;
  914. BOOL isVideo = (messageType == kWCMessageTypeVideoChatAsk || messageType == kWCMessageTypeVideoMeetingInvite) ? YES : NO;
  915. fromUserName = fromUserName.length > 0 ? fromUserName : APP_NAME;
  916. switch ([UIApplication sharedApplication].applicationState) {
  917. case UIApplicationStateActive:
  918. case UIApplicationStateInactive:{
  919. //不处理,显示app接听界面
  920. if (_uuid) {
  921. [self endCall];
  922. }
  923. break;
  924. }
  925. case UIApplicationStateBackground:
  926. default:{
  927. if (isCallKit && !_uuid && [[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
  928. if (_uuid) {
  929. return;
  930. }
  931. _uuid = [NSUUID UUID];
  932. [self applicationWillEnterForeground:[UIApplication sharedApplication]];
  933. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  934. //显示系统CALLKit接听界面
  935. CXCallUpdate * callUpdate = [[CXCallUpdate alloc] init];
  936. callUpdate.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:fromUserName];
  937. callUpdate.hasVideo = NO;
  938. [self.provider reportNewIncomingCallWithUUID:_uuid update:callUpdate completion:^(NSError * _Nullable error) {
  939. if (error) {
  940. NSLog(@"report error:%@",error.description);
  941. }else{
  942. [self performSelector:@selector(endCall) withObject:nil afterDelay:30];
  943. }
  944. }];
  945. });
  946. }else if(isAudio || isVideo){
  947. _uuid = nil;
  948. [self meetingLocalNotifi:fromUserName isAudio:isAudio];
  949. }
  950. break;
  951. }
  952. }
  953. AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  954. }
  955. -(void)meetingLocalNotifi:(NSString *)fromUserName isAudio:(BOOL)isAudio{
  956. UILocalNotification *callNotification = [[UILocalNotification alloc] init];
  957. NSString *stringAlert;
  958. if (isAudio){
  959. stringAlert = [NSString stringWithFormat:@"%@ \n %@", Localized(@"JXMeetingObject_VoiceChat"),fromUserName];
  960. }else{
  961. stringAlert = [NSString stringWithFormat:@"%@\n %@",Localized(@"JXMeetingObject_VideoChat"), fromUserName];
  962. }
  963. callNotification.alertBody = stringAlert;
  964. callNotification.soundName = @"whynotyou.caf";
  965. [[UIApplication sharedApplication]
  966. presentLocalNotificationNow:callNotification];
  967. }
  968. #pragma mark - callKit
  969. - (CXProviderConfiguration *)providerConfig{
  970. static CXProviderConfiguration* configInternal = nil;
  971. static dispatch_once_t onceToken;
  972. dispatch_once(&onceToken, ^{
  973. configInternal = [[CXProviderConfiguration alloc] initWithLocalizedName:APP_NAME];
  974. configInternal.supportsVideo = NO;
  975. configInternal.maximumCallsPerCallGroup = 1;
  976. configInternal.maximumCallGroups = 1;
  977. configInternal.supportedHandleTypes = [NSSet setWithObject:@(CXHandleTypePhoneNumber)];
  978. UIImage* iconMaskImage = [UIImage imageNamed:@"ALOGO_1200"];
  979. configInternal.iconTemplateImageData = UIImagePNGRepresentation(iconMaskImage);
  980. configInternal.ringtoneSound = @"whynotyou.caf";
  981. });
  982. return configInternal;
  983. }
  984. -(CXProvider *)provider{
  985. if (!_provider) {
  986. _provider = [[CXProvider alloc] initWithConfiguration:self.providerConfig];
  987. [_provider setDelegate:self queue:nil];
  988. }
  989. return _provider;
  990. }
  991. -(CXCallController *)cxCallController{
  992. if (!_cxCallController) {
  993. _cxCallController = [[CXCallController alloc] initWithQueue:dispatch_get_main_queue()];
  994. }
  995. return _cxCallController;
  996. }
  997. #pragma mark - CXProviderDelegate
  998. /// Called when the provider has been reset. Delegates must respond to this callback by cleaning up all internal call state (disconnecting communication channels, releasing network resources, etc.). This callback can be treated as a request to end all calls without the need to respond to any actions
  999. - (void)providerDidReset:(CXProvider *)provider{
  1000. NSLog(@"callkit - reset");
  1001. [self endCall];
  1002. }
  1003. -(void)provider:(CXProvider *)provider timedOutPerformingAction:(CXAction *)action{
  1004. NSLog(@"callkit - timeout");
  1005. [self endCall];
  1006. }
  1007. // user answered this incoming call
  1008. - (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action{
  1009. NSLog(@"callkit - answercallaction");
  1010. [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(endCall) object:nil];
  1011. [action fulfill];
  1012. }
  1013. // user end this call
  1014. - (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action{
  1015. NSLog(@"callkit - callend");
  1016. [g_notify postNotificationName:kCallEndNotification object:nil];
  1017. [self endCall];
  1018. [action fulfill];
  1019. }
  1020. - (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession{
  1021. NSLog(@"callkit - callanswer");
  1022. [g_notify postNotificationName:kCallAnswerNotification object:nil];
  1023. }
  1024. - (void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action{
  1025. NSLog(@"callkit - setmuted");
  1026. [g_notify postNotificationName:kCallSetMutedNotification object:[NSNumber numberWithBool:action.muted]];
  1027. }
  1028. - (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSession *)audioSession{
  1029. NSLog(@"callkit - deactivate");
  1030. switch ([UIApplication sharedApplication].applicationState) {
  1031. case UIApplicationStateActive:
  1032. case UIApplicationStateInactive:{
  1033. break;
  1034. }
  1035. case UIApplicationStateBackground:
  1036. default:{
  1037. [self applicationDidEnterBackground:[UIApplication sharedApplication]];
  1038. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1039. exit(0);
  1040. });
  1041. break;
  1042. }
  1043. }
  1044. }
  1045. -(void)endCall{
  1046. // [jxMeeting stopMeeting];
  1047. // [jxMeeting clearMemory];
  1048. // return;
  1049. if (_uuid) {
  1050. NSLog(@"callkit - endcall");
  1051. // self.isShowCall = NO;
  1052. CXEndCallAction * endAction = [[CXEndCallAction alloc] initWithCallUUID:_uuid];
  1053. CXTransaction * trans = [[CXTransaction alloc] initWithAction:endAction];
  1054. CXCallController * callVC = [[CXCallController alloc] initWithQueue:dispatch_get_main_queue()];
  1055. [callVC requestTransaction:trans completion:^(NSError * _Nullable error) {
  1056. if (error) {
  1057. // NSLog(@"%@",error.description);
  1058. [self.provider reportCallWithUUID:_uuid endedAtDate:nil reason:CXCallEndedReasonUnanswered];
  1059. }
  1060. if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
  1061. [self applicationDidEnterBackground:[UIApplication sharedApplication]];
  1062. }
  1063. _uuid = nil;
  1064. }];
  1065. }
  1066. if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
  1067. [self applicationDidEnterBackground:[UIApplication sharedApplication]];
  1068. }
  1069. }
  1070. - (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action {
  1071. NSLog(@"callkit - startcall");
  1072. }
  1073. -(void)callEndInTimeOut{
  1074. NSLog(@"callkit - endintimeout");
  1075. if (_uuid) {
  1076. [self.provider reportCallWithUUID:_uuid endedAtDate:[NSDate dateWithTimeIntervalSinceNow:30] reason:CXCallEndedReasonUnanswered];
  1077. }
  1078. }
  1079. #endif
  1080. #endif
  1081. // 截屏监听
  1082. //- (void)getScreenShot:(NSNotification *)notification{
  1083. // NSLog(@"捕捉截屏事件");
  1084. //
  1085. // //获取截屏图片
  1086. //// UIImage *image = [UIImage imageWithData:[self imageDataScreenShot]];
  1087. // NSData *imageData = [self imageDataScreenShot];
  1088. // BOOL isSuccess = [imageData writeToFile:ScreenShotImage atomically:YES];
  1089. // if (isSuccess) {
  1090. // NSLog(@"截屏存储成功 - %@", NSHomeDirectory());
  1091. // }else {
  1092. // NSLog(@"截屏存储失败");
  1093. // }
  1094. //}
  1095. - (NSData *)imageDataScreenShot
  1096. {
  1097. CGSize imageSize = CGSizeZero;
  1098. imageSize = [UIScreen mainScreen].bounds.size;
  1099. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  1100. CGContextRef context = UIGraphicsGetCurrentContext();
  1101. for (UIWindow *window in [[UIApplication sharedApplication] windows])
  1102. {
  1103. CGContextSaveGState(context);
  1104. CGContextTranslateCTM(context, window.center.x, window.center.y);
  1105. CGContextConcatCTM(context, window.transform);
  1106. CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);
  1107. if ([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
  1108. {
  1109. [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:YES];
  1110. }
  1111. else
  1112. {
  1113. [window.layer renderInContext:context];
  1114. }
  1115. CGContextRestoreGState(context);
  1116. }
  1117. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  1118. UIGraphicsEndImageContext();
  1119. return UIImagePNGRepresentation(image);
  1120. }
  1121. - (void)copyDbWithUserId:(NSString *)userId {
  1122. // 拷贝文件到share extension 共享存储空间中
  1123. userId = [userId uppercaseString];
  1124. NSString* t = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
  1125. NSString* copyPath = [NSString stringWithFormat:@"%@/%@.db",t,userId];
  1126. //获取分组的共享目录
  1127. NSFileManager *manager = [NSFileManager defaultManager];
  1128. NSURL *groupURL = [manager containerURLForSecurityApplicationGroupIdentifier:APP_GROUP_ID];
  1129. NSString *fileName = [NSString stringWithFormat:@"%@.db",userId];
  1130. NSURL *fileURL = [groupURL URLByAppendingPathComponent:fileName];
  1131. NSString *path = [fileURL.absoluteString substringFromIndex:7];
  1132. NSError *error = nil;
  1133. [manager removeItemAtPath:path error:&error];
  1134. if (error) {
  1135. NSLog(@"删除失败error : %@",error);
  1136. }
  1137. if (path.length <= 0) {
  1138. return;
  1139. }
  1140. BOOL isCopy = [manager copyItemAtPath:copyPath toPath:path error:nil];
  1141. if (isCopy) {
  1142. static dispatch_once_t disOnce;
  1143. dispatch_once(&disOnce,^ {
  1144. //只执行一次的代码
  1145. NSLog(@"share extension : %@",path);
  1146. });
  1147. }
  1148. }
  1149. - (void)setupBugly {
  1150. // Get the default config
  1151. BuglyConfig * config = [[BuglyConfig alloc] init];
  1152. // Open the debug mode to print the sdk log message.
  1153. // Default value is NO, please DISABLE it in your RELEASE version.
  1154. //#if DEBUG
  1155. config.debugMode = YES;
  1156. //#endif
  1157. // Open the customized log record and report, BuglyLogLevelWarn will report Warn, Error log message.
  1158. // Default value is BuglyLogLevelSilent that means DISABLE it.
  1159. // You could change the value according to you need.
  1160. // config.reportLogLevel = BuglyLogLevelWarn;
  1161. // Open the STUCK scene data in MAIN thread record and report.
  1162. // Default value is NO
  1163. config.blockMonitorEnable = YES;
  1164. // Set the STUCK THRESHOLD time, when STUCK time > THRESHOLD it will record an event and report data when the app launched next time.
  1165. // Default value is 3.5 second.
  1166. config.blockMonitorTimeout = 1.5;
  1167. // Set the app channel to deployment
  1168. config.channel = @"Bugly";
  1169. config.delegate = self;
  1170. config.consolelogEnable = NO;
  1171. config.viewControllerTrackingEnable = NO;
  1172. // NOTE:Required
  1173. // Start the Bugly sdk with APP_ID and your config
  1174. [Bugly startWithAppId:BUGLY_APP_ID
  1175. #if DEBUG
  1176. developmentDevice:YES
  1177. #endif
  1178. config:config];
  1179. // Set the customizd tag thats config in your APP registerd on the bugly.qq.com
  1180. // [Bugly setTag:1799];
  1181. [Bugly setUserIdentifier:[NSString stringWithFormat:@"User: %@", [UIDevice currentDevice].name]];
  1182. [Bugly setUserValue:[NSProcessInfo processInfo].processName forKey:@"Process"];
  1183. // NOTE: This is only TEST code for BuglyLog , please UNCOMMENT it in your code.
  1184. // [self performSelectorInBackground:@selector(testLogOnBackground) withObject:nil];
  1185. }
  1186. #pragma mark - BuglyDelegate
  1187. - (NSString *)attachmentForException:(NSException *)exception {
  1188. NSLog(@"(%@:%d) %s %@",[[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__,exception);
  1189. return @"This is an attachment";
  1190. }
  1191. #pragma mark - XHLaunchAdDelegate
  1192. /**
  1193. 广告点击事件回调(return YES移除广告,NO不移除广告)
  1194. */
  1195. -(BOOL)xhLaunchAd:(XHLaunchAd *)launchAd clickAtOpenModel:(id)openModel clickPoint:(CGPoint)clickPoint{
  1196. NSLog(@"广告点击事件");
  1197. //openModel即配置广告数据设置的点击广告时打开页面参数(configuration.openModel)
  1198. if(openModel == nil) return NO;
  1199. NSString *urlString = (NSString *)openModel;
  1200. webpageVC *webVC = [webpageVC alloc];
  1201. webVC.isGotoBack = YES;
  1202. webVC.url = urlString;
  1203. webVC = [webVC init];
  1204. // [g_navigation.rootViewController.view addSubview:webVC.view];
  1205. [g_navigation pushViewController:webVC animated:YES];
  1206. return YES;//YES移除广告,NO不移除广告
  1207. }
  1208. - (void)xhLaunchAd:(XHLaunchAd *)launchAd clickSkipButton:(UIButton *)skipButton {
  1209. }
  1210. -(void)xhLaunchAdShowFinish:(XHLaunchAd *)launchAd {
  1211. NSLog(@"广告播放完成");
  1212. // [g_notify postNotificationName:kLaunchAdShowFinishNotifaction object:nil];
  1213. }
  1214. @end