| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- //
- // AppDelegate.m
- // IBOSSMini
- //
- // Created by iHope on 14-6-5.
- // Copyright (c) 2014年 elongtian. All rights reserved.
- //
- #import "AppDelegate.h"
- #import "LoginViewController.h"
- #import "MainTabVC.h"
- @interface AppDelegate(){
- // app store 升级url
- NSString *trackViewURL;
- }
- @property(strong,nonatomic) ASIDownManager * mDownManager ;
- @property(strong,nonatomic) UIView *loadView;
- @end
- @implementation AppDelegate
- /**
- 登陆主页
- */
- -(void)changeViewDidLogin {
- MainTabVC *mainVC = [[MainTabVC alloc] init];
- self.window.rootViewController = mainVC;//mainVC.tabBarController;
- }
- /**
- 登陆页
- */
- -(void)changeViewDidLogout {
- LoginViewController *loginVC = [[LoginViewController alloc] init];
- self.window.rootViewController = loginVC;
-
- }
- /**
- 自动登录
- */
- -(void)autoLogin
- {
- LoginViewController *loginVC = [[LoginViewController alloc] init];
- loginVC.autoLogin = YES;
- self.window.rootViewController = loginVC;
- }
- /**
- 程序启动
- @param application <#application description#>
- @param launchOptions <#launchOptions description#>
- @return <#return value description#>
- */
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- // [self request];
- // IOS判断app在appstore是否有可用的更新
- [self checkVersion];
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
- [self ShowLoadView:nil];
- // Override point for customization after application launch.
- if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){
- [[UINavigationBar appearance] setBarTintColor:NavColor];
- }
- [self.window makeKeyAndVisible];
-
- return YES;
- }
- /**
- 请求下数据,弹出允许网络权限
- */
- - (void)request {
- if(!kkFirstLogin){
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager.delegate = self;
- [self.mDownManager postHttpRequest:@"www.baidu.com" dic:nil path:nil fileName:nil];
- kkFirstLogin = @"ok";
- }
- }
- /**
- IOS判断app在appstore是否有可用的更新
- */
- - (void)checkVersion{
- self.mDownManager = [[ASIDownManager alloc] init];
- self.mDownManager.delegate = self;
- self.mDownManager.OnImageDown = @selector(onRequestSuccess:) ;
- [self.mDownManager postHttpRequest:@"http://itunes.apple.com/lookup?id=1084263229" dic:nil path:nil fileName:nil];
- }
- /**
- 请求数据成功
-
- @param d <#d description#>
- */
- - (void)onRequestSuccess:(ASIDownManager *)sender{
- NSDictionary *resultDic = [sender.mWebStr JSONValue];
- NSArray *infoArray = [resultDic objectForKey:@"results"];
- if (infoArray.count > 0) {
- NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
- NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
- NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
-
- NSArray *curVerArr = [currentVersion componentsSeparatedByString:@"."];
- NSArray *appstoreVerArr = [appStoreVersion componentsSeparatedByString:@"."];
- BOOL needUpdate = NO;
- //比较版本号大小
- int maxv = (int)MAX(curVerArr.count, appstoreVerArr.count);
- int cver = 0;
- int aver = 0;
- for (int i = 0; i < maxv; i++) {
- if (appstoreVerArr.count > i) {
- aver = [NSString stringWithFormat:@"%@",appstoreVerArr[i]].intValue;
- }
- else{
- aver = 0;
- }
- if (curVerArr.count > i) {
- cver = [NSString stringWithFormat:@"%@",curVerArr[i]].intValue;
- }
- else{
- cver = 0;
- }
- if (aver > cver) {
- needUpdate = YES;
- break;
- }
- }
-
- //如果有可用的更新
- if (needUpdate){
- trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];//trackViewURL临时变量存储app下载地址,可以让app跳转到appstore
- UIAlertView* alertview =[[UIAlertView alloc] initWithTitle:@"版本升级" message:[NSString stringWithFormat:@"发现有新版本,是否升级?"] delegate:self cancelButtonTitle:@"暂不升级" otherButtonTitles:@"马上升级", nil];
- [alertview show];
- }
- }
- }
- /**
- app下载地址,可以让app跳转到appstore
-
- @param alertView <#alertView description#>
- @param buttonIndex <#buttonIndex description#>
- */
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- if (buttonIndex == 1){
- UIApplication *application = [UIApplication sharedApplication];
- [application openURL:[NSURL URLWithString:trackViewURL]];
- }
- }
- /**
- view
- @param view <#view description#>
- */
- - (void)ShowLoadView:(UIView *)view {
- //没有自动登录
- if(kkAutoLogin==nil||[[NSString stringWithFormat:@"%@",kkAutoLogin ]isEqualToString:@"0"]){
- [self changeViewDidLogout];
-
- }
- else {//自动登录了
- if(kkSessionKey!=nil&&![kkSessionKey isEqualToString:@""]){
- [self autoLogin];
- }
- else{
- [self changeViewDidLogout];
- }
- }
- }
- /**
- 回调成功
- @param sender <#sender description#>
- */
- - (void)OnLoadFinish:(ASIDownManager *)sender {
-
- NSDictionary *dic = [sender.mWebStr JSONValue];
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- int result = [[dic objectForKey:@"result"] intValue];
- if(result==1)
- {
- @autoreleasepool {
- [_loadView removeFromSuperview];
- }
- }
- else
- {
- exit(0);
- }
- }
-
- }
- /**
- 回调失败
- @param sender <#sender description#>
- */
- - (void)OnLoadFail:(ASIDownManager *)sender {
- }
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- }
- @end
|