AppDelegate.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. //
  2. // AppDelegate.m
  3. // IBOSSMini
  4. //
  5. // Created by iHope on 14-6-5.
  6. // Copyright (c) 2014年 elongtian. All rights reserved.
  7. //
  8. #import "AppDelegate.h"
  9. #import "LoginViewController.h"
  10. #import "MainTabVC.h"
  11. @interface AppDelegate(){
  12. // app store 升级url
  13. NSString *trackViewURL;
  14. }
  15. @property(strong,nonatomic) ASIDownManager * mDownManager ;
  16. @property(strong,nonatomic) UIView *loadView;
  17. @end
  18. @implementation AppDelegate
  19. /**
  20. 登陆主页
  21. */
  22. -(void)changeViewDidLogin {
  23. MainTabVC *mainVC = [[MainTabVC alloc] init];
  24. self.window.rootViewController = mainVC;//mainVC.tabBarController;
  25. }
  26. /**
  27. 登陆页
  28. */
  29. -(void)changeViewDidLogout {
  30. LoginViewController *loginVC = [[LoginViewController alloc] init];
  31. self.window.rootViewController = loginVC;
  32. }
  33. /**
  34. 自动登录
  35. */
  36. -(void)autoLogin
  37. {
  38. LoginViewController *loginVC = [[LoginViewController alloc] init];
  39. loginVC.autoLogin = YES;
  40. self.window.rootViewController = loginVC;
  41. }
  42. /**
  43. 程序启动
  44. @param application <#application description#>
  45. @param launchOptions <#launchOptions description#>
  46. @return <#return value description#>
  47. */
  48. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  49. {
  50. // [self request];
  51. // IOS判断app在appstore是否有可用的更新
  52. [self checkVersion];
  53. self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  54. [self ShowLoadView:nil];
  55. // Override point for customization after application launch.
  56. if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
  57. [[UINavigationBar appearance] setBarTintColor:NavColor];
  58. }
  59. [self.window makeKeyAndVisible];
  60. return YES;
  61. }
  62. /**
  63. 请求下数据,弹出允许网络权限
  64. */
  65. - (void)request {
  66. if(!kkFirstLogin){
  67. self.mDownManager = [[ASIDownManager alloc] init];
  68. self.mDownManager.delegate = self;
  69. [self.mDownManager postHttpRequest:@"www.baidu.com" dic:nil path:nil fileName:nil];
  70. kkFirstLogin = @"ok";
  71. }
  72. }
  73. /**
  74. IOS判断app在appstore是否有可用的更新
  75. */
  76. - (void)checkVersion{
  77. self.mDownManager = [[ASIDownManager alloc] init];
  78. self.mDownManager.delegate = self;
  79. self.mDownManager.OnImageDown = @selector(onRequestSuccess:) ;
  80. [self.mDownManager postHttpRequest:@"http://itunes.apple.com/lookup?id=1084263229" dic:nil path:nil fileName:nil];
  81. }
  82. /**
  83. 请求数据成功
  84. @param d <#d description#>
  85. */
  86. - (void)onRequestSuccess:(ASIDownManager *)sender{
  87. NSDictionary *resultDic = [sender.mWebStr JSONValue];
  88. NSArray *infoArray = [resultDic objectForKey:@"results"];
  89. if (infoArray.count > 0) {
  90. NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
  91. NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
  92. NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
  93. NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
  94. NSArray *curVerArr = [currentVersion componentsSeparatedByString:@"."];
  95. NSArray *appstoreVerArr = [appStoreVersion componentsSeparatedByString:@"."];
  96. BOOL needUpdate = NO;
  97. //比较版本号大小
  98. int maxv = (int)MAX(curVerArr.count, appstoreVerArr.count);
  99. int cver = 0;
  100. int aver = 0;
  101. for (int i = 0; i < maxv; i++) {
  102. if (appstoreVerArr.count > i) {
  103. aver = [NSString stringWithFormat:@"%@",appstoreVerArr[i]].intValue;
  104. }
  105. else{
  106. aver = 0;
  107. }
  108. if (curVerArr.count > i) {
  109. cver = [NSString stringWithFormat:@"%@",curVerArr[i]].intValue;
  110. }
  111. else{
  112. cver = 0;
  113. }
  114. if (aver > cver) {
  115. needUpdate = YES;
  116. break;
  117. }
  118. }
  119. //如果有可用的更新
  120. if (needUpdate){
  121. trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];//trackViewURL临时变量存储app下载地址,可以让app跳转到appstore
  122. UIAlertView* alertview =[[UIAlertView alloc] initWithTitle:@"版本升级" message:[NSString stringWithFormat:@"发现有新版本,是否升级?"] delegate:self cancelButtonTitle:@"暂不升级" otherButtonTitles:@"马上升级", nil];
  123. [alertview show];
  124. }
  125. }
  126. }
  127. /**
  128. app下载地址,可以让app跳转到appstore
  129. @param alertView <#alertView description#>
  130. @param buttonIndex <#buttonIndex description#>
  131. */
  132. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  133. {
  134. if (buttonIndex == 1){
  135. UIApplication *application = [UIApplication sharedApplication];
  136. [application openURL:[NSURL URLWithString:trackViewURL]];
  137. }
  138. }
  139. /**
  140. view
  141. @param view <#view description#>
  142. */
  143. - (void)ShowLoadView:(UIView *)view {
  144. //没有自动登录
  145. if(kkAutoLogin==nil||[[NSString stringWithFormat:@"%@",kkAutoLogin ]isEqualToString:@"0"]){
  146. [self changeViewDidLogout];
  147. }
  148. else {//自动登录了
  149. if(kkSessionKey!=nil&&![kkSessionKey isEqualToString:@""]){
  150. [self autoLogin];
  151. }
  152. else{
  153. [self changeViewDidLogout];
  154. }
  155. }
  156. }
  157. /**
  158. 回调成功
  159. @param sender <#sender description#>
  160. */
  161. - (void)OnLoadFinish:(ASIDownManager *)sender {
  162. NSDictionary *dic = [sender.mWebStr JSONValue];
  163. if (dic && [dic isKindOfClass:[NSDictionary class]]) {
  164. int result = [[dic objectForKey:@"result"] intValue];
  165. if(result==1)
  166. {
  167. @autoreleasepool {
  168. [_loadView removeFromSuperview];
  169. }
  170. }
  171. else
  172. {
  173. exit(0);
  174. }
  175. }
  176. }
  177. /**
  178. 回调失败
  179. @param sender <#sender description#>
  180. */
  181. - (void)OnLoadFail:(ASIDownManager *)sender {
  182. }
  183. - (void)applicationWillResignActive:(UIApplication *)application
  184. {
  185. }
  186. - (void)applicationDidEnterBackground:(UIApplication *)application
  187. {
  188. }
  189. - (void)applicationWillEnterForeground:(UIApplication *)application
  190. {
  191. }
  192. - (void)applicationDidBecomeActive:(UIApplication *)application
  193. {
  194. }
  195. - (void)applicationWillTerminate:(UIApplication *)application
  196. {
  197. }
  198. @end