關(guān)于應(yīng)用的版本更新提示

http://www.cnblogs.com/jys509/p/5390505.html從這邊看到的

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self hsUpdateApp];
}
-(void)hsUpdateApp
{
    //2先獲取當(dāng)前工程項(xiàng)目版本號
    NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
    NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
    
    //3從網(wǎng)絡(luò)獲取appStore版本號
    NSError *error;
    NSData *response = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@",APPID]]] returningResponse:nil error:nil];
    if (response == nil) {
        NSLog(@"你沒有連接網(wǎng)絡(luò)哦");
        return;
    }
    NSDictionary *appInfoDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
    if (error) {
        NSLog(@"hsUpdateAppError:%@",error);
        return;
    }
    NSArray *array = appInfoDic[@"results"];
    NSDictionary *dic = array[0];
    NSString *appStoreVersion = dic[@"version"];
    //打印版本號
    NSLog(@"當(dāng)前版本號:%@\n商店版本號:%@",currentVersion,appStoreVersion);
    //4當(dāng)前版本號小于商店版本號,就更新
    if([currentVersion compare:appStoreVersion options:NSNumericSearch] ==  NSOrderedAscending)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本有更新" message:[NSString stringWithFormat:@"檢測到新版本(%@),是否更新?",appStoreVersion] delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"更新",nil];
        [alert show];
    }else{
        NSLog(@"版本號好像比商店大噢!檢測到不需要更新");
    }
    
}

- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //5實(shí)現(xiàn)跳轉(zhuǎn)到應(yīng)用商店進(jìn)行更新
    if(buttonIndex==1)
    {
        //6此處加入應(yīng)用在app store的地址,方便用戶去更新,一種實(shí)現(xiàn)方式如下:
        NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@", APPID]];
        [[UIApplication sharedApplication] openURL:url];
    }
}

用于記錄下以后可能用到
但是現(xiàn)在的appstore不會通過這樣的功能
所以你只能與服務(wù)器的版本相互匹配.來實(shí)現(xiàn)提醒更新

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容