AppDelegate.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. //
  2. // AppDelegate.m
  3. // JSJPCoach
  4. //
  5. // Created by apple on 2017/3/10.
  6. // Copyright © 2017年 Danson. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "ViewController.h"
  10. #import "LoginVC.h"
  11. #import "ADView.h"
  12. #import "MyMsgVC.h"
  13. #import <SMS_SDK/SMSSDK.h>
  14. #import "MyUINavigationController.h"
  15. #import "TerminalScreenVC.h"
  16. #import "MyPlanVC.h"
  17. #import <IQKeyboardManager/IQKeyboardManager.h>
  18. //bugly腾讯bug统计
  19. #import <Bugly/Bugly.h>
  20. @interface AppDelegate ()<UIScrollViewDelegate,UIAlertViewDelegate,BMKGeneralDelegate,BMKLocationAuthDelegate,GeTuiSdkDelegate, UNUserNotificationCenterDelegate>
  21. {
  22. UIScrollView* scroll;
  23. //no use
  24. NSString *pushType;
  25. NSString *pushID;
  26. }
  27. @end
  28. @implementation AppDelegate
  29. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  30. //异常统计
  31. #ifdef DEBUG
  32. //do sth1.
  33. #else
  34. [Bugly startWithAppId:BUGLY_APP_ID];
  35. #endif
  36. [IQKeyboardManager sharedManager].enable = YES;
  37. //个推
  38. // 通过个推平台分配的appId、 appKey 、appSecret 启动SDK,注:该方法需要在主线程中调用
  39. [GeTuiSdk startSdkWithAppId:kGtAppId appKey:kGtAppKey appSecret:kGtAppSecret delegate:self];
  40. // 注册 APNs
  41. [self registerRemoteNotification];
  42. //短信验证
  43. // [SMSSDK registerApp:@"1bfe5470936a0" withSecret:@"f4d4ccfc31db2bd3c6bf0ac500262bb4"];
  44. self.window = [[UIWindow alloc] initWithFrame:kFrame];
  45. //初始化地图
  46. _mapManager = [[BMKMapManager alloc]init];
  47. // 如果要关注网络及授权验证事件,请设定 generalDelegate参数
  48. BOOL ret = [_mapManager start:BaiDuMapAK generalDelegate:self];
  49. if (!ret) {
  50. //NSLog(@"%d",ret);
  51. NSLog(@"manager start failed!");
  52. }
  53. //百度地图定位
  54. [[BMKLocationAuth sharedInstance] checkPermisionWithKey:BaiDuMapAK authDelegate:self];
  55. /*
  56. 若用户点击icon启动,lauchOptions内无数据
  57. */
  58. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  59. //didReceiveNotificationResponse 统一处理
  60. #else
  61. //远程通知
  62. if (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey])
  63. {
  64. //关于这个方法远程和进程不一样 一个是userinfo字典。一个是本地通知
  65. NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
  66. //这里不用判断重复消息
  67. NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1];
  68. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  69. [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"];
  70. [userDefaults synchronize];
  71. NSString *jsonStr = userInfo[@"payload"];
  72. if ([jsonStr length] != 0) {
  73. NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
  74. if (data) {
  75. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  76. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  77. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  78. if (payloadDic == nil) {
  79. return;
  80. }
  81. if (pushType != 0) {
  82. [self gotoPush];
  83. }else{
  84. //其它信息
  85. [self gotoLoad];
  86. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  87. }
  88. return YES;
  89. }
  90. }
  91. }
  92. #endif
  93. loadADPaths();
  94. [self getAppParam];
  95. //判断跳转页面 这样每次更新版本 都会有导航页
  96. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  97. NSString *vesionNow = [infoDic objectForKey:@"CFBundleShortVersionString"];
  98. if (![defUser.isWelcomed isEqualToString:vesionNow]) {
  99. //刚刚下载 要加载一次广告 存本地
  100. defUser.isWelcomed = vesionNow;
  101. [self makeLaunchView];
  102. loadADPaths();
  103. }else{
  104. //在这里搞个 广告页面 加载广告
  105. // [ADView showADView];
  106. @try {
  107. //是否为新版本
  108. //[self onCheckVersion];
  109. }
  110. @catch (NSException *exception) {
  111. }
  112. @finally {
  113. [self gotoLoad];
  114. }
  115. }
  116. [self.window makeKeyAndVisible];
  117. [RQ_AD_MANAGER loadAdWithAdType:RQADType_Splash customView:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
  118. return YES;
  119. }
  120. #pragma mark 推送注册
  121. /** 注册 APNs */
  122. - (void)registerRemoteNotification {
  123. /*
  124. 警告:Xcode8 需要手动开启"TARGETS -> Capabilities -> Push Notifications"
  125. */
  126. if ([[UIDevice currentDevice].systemVersion floatValue] >= 10.0) {
  127. UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  128. center.delegate = self;
  129. [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionCarPlay) completionHandler:^(BOOL granted, NSError *_Nullable error) {
  130. if (!error) {
  131. NSLog(@"request authorization succeeded!(iOS >= 10.0)");
  132. }
  133. }];
  134. } else if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
  135. UIUserNotificationType types = (UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge);
  136. UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
  137. [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
  138. }
  139. //远程需添加
  140. [[UIApplication sharedApplication] registerForRemoteNotifications];
  141. }
  142. /** 远程通知注册成功委托 */
  143. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  144. NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
  145. token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
  146. NSLog(@"\n>>>[DeviceToken Success]:%@\n\n", token);
  147. // 向个推服务器注册deviceToken
  148. [GeTuiSdk registerDeviceToken:token];
  149. }
  150. /** 远程通知注册失败委托 */
  151. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  152. NSLog(@"FailToRegisterForRemoteNotificationsWithError:%@",error);
  153. }
  154. //iOS7.0 以后支持 APP 后台刷新数据,会回调 performFetchWithCompletionHandler 接口。为保证个推SDK的数据刷新,需在该回调接口中调用[GeTuiSdk resume]方法帮助个推 SDK 刷新数据。
  155. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  156. /// Background Fetch 恢复SDK 运行
  157. [GeTuiSdk resume];
  158. completionHandler(UIBackgroundFetchResultNewData);
  159. }
  160. #pragma mark - iOS < 10
  161. //------远程推送
  162. //处理APNs 通知点击事件,统计有效用户点击数
  163. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
  164. NSLog(@"didReceiveRemoteNotification and iOS<10");
  165. // 将收到的APNs信息传给个推统计
  166. [GeTuiSdk handleRemoteNotification:userInfo];
  167. completionHandler(UIBackgroundFetchResultNewData);
  168. [self remoteNotificationDealWithPayLoadDic:userInfo];
  169. }
  170. #pragma mark iOS > 10
  171. /*
  172. 1.对于iOS 10 及以后版本,为处理 APNs 通知点击,统计有效用户点击数,需先添加 UNUserNotificationCenterDelegate
  173. 2.app可以处于任何状态(terminate,前/后台)
  174. */
  175. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  176. - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
  177. NSLog(@"willPresentNotification and iOS>10前台:%@", notification.request.content.userInfo);
  178. // 根据APP需要,判断是否要提示用户Badge、Sound、Alert(ios>10 如果需要应用在前台也展示通知)
  179. completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
  180. }
  181. // iOS 10: 统一获取推送的接口 点击通知进入App时触发,在该方法内统计有效用户点击数 (点击弹窗,不管app处于任何状态(terminate,前/后台)都会调用)
  182. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  183. NSLog(@"didReceiveNotificationResponse iOS>10:%@", response.notification.request.content.userInfo);
  184. //远程推送
  185. //将收到的APNs信息传给个推统计
  186. [GeTuiSdk handleRemoteNotification:response.notification.request.content.userInfo];
  187. completionHandler();
  188. NSDictionary* userInfo = response.notification.request.content.userInfo;
  189. [self remoteNotificationDealWithPayLoadDic:userInfo];
  190. }
  191. #endif
  192. #pragma mark - 个推相关方法
  193. /** SDK启动成功返回cid */
  194. - (void)GeTuiSdkDidRegisterClient:(NSString *)clientId {
  195. //个推SDK已注册,返回clientId
  196. NSLog(@"\n>>>[GeTuiSdk RegisterClient]:%@\n\n", clientId);
  197. myDelegate.token = clientId;
  198. // upLoadToken();
  199. }
  200. /** SDK遇到错误回调 */
  201. - (void)GeTuiSdkDidOccurError:(NSError *)error {
  202. //个推错误报告,集成步骤发生的任何错误都在这里通知,如果集成后,无法正常收到消息,查看这里的通知。
  203. NSLog(@"\n>>>[GexinSdk error]:%@\n\n", [error localizedDescription]);
  204. }
  205. /** SDK收到透传消息回调 */
  206. - (void)GeTuiSdkDidReceivePayloadData:(NSData *)payloadData andTaskId:(NSString *)taskId andMsgId:(NSString *)msgId andOffLine:(BOOL)offLine fromGtAppId:(NSString *)appId {
  207. //收到个推消息
  208. if (payloadData) {
  209. NSString * payloadMsg = [[NSString alloc] initWithBytes:payloadData.bytes length:payloadData.length encoding:NSUTF8StringEncoding];
  210. NSLog(@"GeTuiSdkDidReceivepayloadMsg:%@",payloadMsg);
  211. //判断是否被处理过[即发送离线消息的时候,会走apns+个推sdk(有效期内)]
  212. //ps:这里处理之后不做存档操作,保证点击通知栏的时候可以”再处理一次“
  213. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  214. NSString *oldmsgId = [userDefaults objectForKey:@"remoteNotifymsgId"];
  215. if ([oldmsgId isEqualToString:msgId]) {
  216. return;
  217. }
  218. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:payloadData options:NSJSONReadingMutableContainers error:nil];
  219. if (payloadDic.count == 0) {
  220. return;
  221. }
  222. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  223. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  224. if ([pushType integerValue] != 0) {
  225. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:payloadDic[@"title"] message:payloadDic[@"body"] preferredStyle:UIAlertControllerStyleAlert];
  226. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  227. }]];
  228. [alertFind addAction:[UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  229. [self gotoPush];
  230. }]];
  231. [self.window.rootViewController presentViewController:alertFind animated:true completion:nil];
  232. }else{
  233. //其它信息
  234. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  235. }
  236. }
  237. }
  238. #pragma mark 远程通知的数据处理
  239. -(void)remoteNotificationDealWithPayLoadDic:(NSDictionary *)userInfo{
  240. /*
  241. {
  242. "_ge_" = 1;
  243. "_gmid_" = "OSL-0818_bJ6zVRy8cC6JsflZOYPXO9:965f14a1051748c4a48f9db2437362e5:d48422d462d2bcf0b9d962f150b235b9";
  244. "_gurl_" = "sdk.open.extension.getui.com:8123";
  245. aps = {
  246. alert = {
  247. body = "\U60a8\U9a7e\U6821\U6709\U8f66\U8f86\U7ec8\U7aef\U62a5\U8b66\U9700\U89e3\U9664\Uff0c\U8bf7\U67e5\U770b\U5e76\U5904\U7406";
  248. title = "\U544a\U8b66\U6d88\U606f";
  249. };
  250. badge = 2;
  251. category = "button\U663e\U793a";
  252. "content-available" = 1;
  253. "mutable-content" = 1;
  254. sound = default;
  255. };
  256. payload = "{\"title\":\"\U544a\U8b66\U6d88\U606f\",\"code\":\"1\",\"body\":\"\U60a8\U9a7e\U6821\U6709\U8f66\U8f86\U7ec8\U7aef\U62a5\U8b66\U9700\U89e3\U9664\Uff0c\U8bf7\U67e5\U770b\U5e76\U5904\U7406\,\"id\":\"2\"}";
  257. }
  258. */
  259. // _gmid_对应-- taskId msgId clientID
  260. //这里使用msgid判断是否被处理【不过似乎应该用taskid?@lee,幻想着一个任务多条消息]
  261. NSString *msgId = [userInfo[@"_gmid_"] componentsSeparatedByString:@":"][1];
  262. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
  263. NSString *oldMsgId = [userDefaults objectForKey:@"remoteNotifymsgId"];
  264. if ([msgId isEqualToString:oldMsgId]) {
  265. return;
  266. }
  267. //开始处理
  268. [userDefaults setObject:msgId forKey:@"remoteNotifymsgId"];
  269. [userDefaults synchronize];
  270. NSString *jsonStr = userInfo[@"payload"];
  271. if ([jsonStr length] == 0) {
  272. return;
  273. }
  274. NSData *data = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
  275. if (data) {
  276. NSDictionary * payloadDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  277. if (payloadDic == nil) {
  278. return;
  279. }
  280. pushType = [NSString stringWithFormat:@"%@",payloadDic[@"code"]];
  281. pushID = [NSString stringWithFormat:@"%@",payloadDic[@"id"]];
  282. if (pushType != 0) {
  283. [self gotoPush];
  284. }else{
  285. //其它信息
  286. [self showMsgByArertWithTitle:payloadDic[@"title"] message:payloadDic[@"body"]];
  287. }
  288. }
  289. }
  290. -(void)showMsgByArertWithTitle:(NSString *)title message:(NSString *)message{
  291. if (message.length == 0) {
  292. return;
  293. }
  294. //其它信息
  295. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
  296. [alertFind addAction:[UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  297. }]];
  298. [self.window.rootViewController presentViewController:alertFind animated:true completion:nil];
  299. }
  300. #pragma mark 跳转相关
  301. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  302. {
  303. if (alertView.tag == 10000) {
  304. if (buttonIndex == 1) {
  305. NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/jiao-lian-guan-jia-kua-jia-xiao-ban/id1214203182?l=en&mt=8"];
  306. [[UIApplication sharedApplication]openURL:url];
  307. }
  308. }else{
  309. if (buttonIndex != alertView.cancelButtonIndex) {
  310. [self gotoPush];
  311. }
  312. }
  313. }
  314. -(void)gotoPush
  315. {
  316. //4:消息 6:预约 7:学员签到提醒
  317. switch ([pushType integerValue]) {
  318. case 4:
  319. [self goToMessage];
  320. break;
  321. case 6:
  322. [self goToMyPlanVC];
  323. break;
  324. case 7:
  325. [self goToTerminalScreenVC];
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. -(void)goToTerminalScreenVC
  332. {
  333. TerminalScreenVC* vc = [[TerminalScreenVC alloc] init];
  334. vc.isNotification = YES;
  335. MyUINavigationController *nav = [[MyUINavigationController alloc]initWithRootViewController:vc];
  336. [myDelegate.window setRootViewController:nav];
  337. }
  338. -(void)goToMyPlanVC
  339. {
  340. MyPlanVC* vc = [[MyPlanVC alloc] init];
  341. vc.isNotification = YES;
  342. MyUINavigationController *nav = [[MyUINavigationController alloc]initWithRootViewController:vc];
  343. [myDelegate.window setRootViewController:nav];
  344. }
  345. -(void)goToMessage
  346. {
  347. MyMsgVC* vc = [[MyMsgVC alloc] init];
  348. vc.isNotification = YES;
  349. MyUINavigationController *nav = [[MyUINavigationController alloc]initWithRootViewController:vc];
  350. [myDelegate.window setRootViewController:nav];
  351. }
  352. #pragma mark -
  353. //程序挂起
  354. - (void)applicationWillResignActive:(UIApplication *)application {
  355. }
  356. //程序进入后台
  357. - (void)applicationDidEnterBackground:(UIApplication *)application {
  358. myDelegate.isBackgroundTask = YES;
  359. }
  360. //程序到前台
  361. - (void)applicationWillEnterForeground:(UIApplication *)application {
  362. //[ADView showADView];
  363. }
  364. //程序复原
  365. - (void)applicationDidBecomeActive:(UIApplication *)application
  366. {
  367. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  368. myDelegate.isBackgroundTask = NO;
  369. }
  370. - (void)applicationWillTerminate:(UIApplication *)application {
  371. NSLog(@"程序意外退出");
  372. }
  373. #pragma mark 检查新旧
  374. -(void)onCheckVersion
  375. {
  376. if (![Util connectedToNetWork])
  377. {
  378. return;
  379. }
  380. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  381. NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  382. NSString *URL = @"http://itunes.apple.com/lookup?id=1214203182";
  383. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  384. [request setURL:[NSURL URLWithString:URL]];
  385. [request setHTTPMethod:@"POST"];
  386. NSOperationQueue *queue=[NSOperationQueue mainQueue];
  387. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  388. if (!data) {
  389. return;
  390. }
  391. //如果data等于nil的时候 再去解析 会发生崩溃
  392. NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
  393. if (!dic) {
  394. return;
  395. }
  396. NSArray *infoArray = [dic objectForKey:@"results"];
  397. if ([infoArray count]) {
  398. NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
  399. NSString *lastVersion = [releaseInfo objectForKey:@"version"];
  400. //NSLog(@"AppStore-->%@,手机上-->%@",lastVersion,currentVersion);
  401. NSInteger lastInt = [[lastVersion substringToIndex:1] integerValue];
  402. NSInteger currInt = [[currentVersion substringToIndex:1] integerValue];
  403. //NSLog(@"%d,%d",(int)lastInt,(int)currInt);
  404. if (lastInt > currInt) {
  405. [self updateVersion];
  406. }else{
  407. double lastDoub = [[lastVersion substringWithRange:NSMakeRange(2, 3)]doubleValue];
  408. double currDoub = [[currentVersion substringWithRange:NSMakeRange(2, 3)]doubleValue];
  409. //NSLog(@"aa-->%f---bb--->%f",lastDoub,currDoub);
  410. if (lastDoub > currDoub) {
  411. // NSLog(@"更新");
  412. [self updateVersion];
  413. }else{
  414. //已是最新版
  415. //NSLog(@"不更");
  416. }
  417. }
  418. }
  419. }];
  420. }
  421. -(void)updateVersion
  422. {
  423. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新提示" message:@"有新的版本发布,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
  424. alert.tag = 10000;
  425. [alert show];
  426. }
  427. #pragma mark - 欢迎页面
  428. -(void)makeLaunchView
  429. {
  430. NSArray* images = @[@"welcom_page_21.jpg",@"welcom_page_22.jpg",@"welcom_page_23.jpg",@"welcom_page_24.jpg"];
  431. //关于导航页要修改 添上新的导航页
  432. scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSize.width, kSize.height)];
  433. /**跳到第4页,也会欢迎结束。
  434. */
  435. [scroll setContentSize:CGSizeMake(kSize.width* images.count+kSize.width, 0)];
  436. [scroll setBackgroundColor:[UIColor orangeColor]];
  437. [scroll setShowsHorizontalScrollIndicator:NO];
  438. [scroll setDelegate:self];
  439. scroll.pagingEnabled = YES;
  440. UIViewController* vc = [UIViewController new];
  441. [vc.view addSubview:scroll];
  442. [self.window setRootViewController:vc];
  443. UIImageView* iv;
  444. for (int i =0; i<images.count; i++) {
  445. iv = [[UIImageView alloc] initWithFrame:kFrame];
  446. iv.x = kSize.width*i;
  447. [scroll addSubview:iv];
  448. [iv setImage:[UIImage imageNamed:images[i]]];
  449. }
  450. UIButton* btn = [[UIButton alloc] initWithFrame:iv.frame];
  451. [scroll addSubview:btn];
  452. [btn addTarget:self action:@selector(gotoLoad) forControlEvents:UIControlEventTouchUpInside];
  453. myDelegate.adIsShow = YES;
  454. }
  455. -(void)gotoLoad
  456. {
  457. ViewController *vc = [ViewController new];
  458. MyUINavigationController *nav = [[MyUINavigationController alloc] initWithRootViewController:vc];
  459. nav.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  460. self.window.rootViewController = nav;
  461. }
  462. -(void)scrollViewDidScroll:(UIScrollView *)scrollView
  463. {
  464. CGPoint off = scrollView.contentOffset;
  465. if (off.x / kSize.width > 3.9) {
  466. [self gotoLoad];
  467. }
  468. }
  469. - (void)getAppParam {
  470. NSMutableArray *arr = [NSMutableArray array];
  471. [arr addPro:@"dqbh" Value:[NSString stringWithFormat:@"%@",defUser.userDict[@"city"]? : ([defUser.userDict[@"city"] isEqualToString:@"(null)"]? @"" : @"")]];
  472. NSString *method= @"getAppParam";
  473. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  474. if ([dict[@"code"] isEqualToString:@"0"]) {
  475. if ([dict [@"body"] isKindOfClass:[NSArray class]]) {
  476. NSArray *array = dict [@"body"];
  477. [array.rac_sequence.signal subscribeNext:^(NSDictionary *dic) {
  478. [RQ_SHARE_FUNCTION saveObjectWithObject:dic[@"VALUE"] ForKey:dic[@"KEY"]];
  479. }];
  480. }
  481. }
  482. }];
  483. }
  484. @end