你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios開發之APP升級的實現

ios開發之APP升級的實現

編輯:IOS開發綜合
直接上代碼:
/**
 *  檢測軟件是否需要升級
 */
-(void)checkVersion
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@http://itunes.apple.com/cn/lookup?id=%i,iFeverAPPID]];
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:url];
    [request setUseCookiePersistence:YES];
    [request setDelegate: self];
    [request setDidFailSelector:@selector(getVersionRequestFailed:)];
    [request setDidFinishSelector:@selector(getVersionRequestSuccess:)];
    [request startAsynchronous];//開始異步請求
}

-(void)getVersionRequestFailed:(ASIHTTPRequest *)request1
{
    NSLog(@從AppStore獲取版本信息失敗!!);
}

-(void)getVersionRequestSuccess:(ASIHTTPRequest *)request1
{
    NSString *newVersion;
    NSData *responseData = [request1 responseData];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
    NSArray *resultArray = [dic objectForKey:@results];
    for (id config in resultArray) {
        newVersion = [config valueForKey:@version];
    }
    if (newVersion) {
        NSLog(@通過AppStore獲取的版本號是:%@,newVersion);
    }
    //獲取本地版本號
    NSString *localVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@CFBundleVersion];
    NSString *msg = [NSString stringWithFormat:@你當前的版本是V%@,發現新版本V%@,是否下載新版本?,localVersion,newVersion];
    if ([newVersion floatValue] > [localVersion floatValue]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@升級提示! message:msg delegate:self cancelButtonTitle:@下次再說 otherButtonTitles:@現在升級, nil];
        alert.tag = kVersionNeedUpdateAlertTag;
        [alert show];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == kVersionNeedUpdateAlertTag) {
        //軟件需要更新提醒
        if (buttonIndex == 1) {
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%i?mt=8,iFeverAPPID]];
            [[UIApplication sharedApplication]openURL:url];
            /*
             // 打開iTunes 方法二:此方法總是提示“無法連接到itunes”,不推薦使用
             NSString *iTunesLink = @itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8;
             NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8,iFeverAPPID]];
             [[UIApplication sharedApplication] openURL:url];
             */
        }
    }
}

 

如果想知道網絡請求AppStore時返回的信息可以打開這個鏈接:http://itunes.apple.com/cn/lookup?id=465039730

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved