ios開發之APP升級的實現

來源:互聯網
上載者:User

ios開發之APP升級的實現
直接上代碼:

/** *  檢測軟體是否需要升級 */-(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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.