檢測線上是否有新版本發(fā)布
- (void)versionUpdate{
//獲得當前發(fā)布的版本
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
//耗時的操作---獲取某個應用在AppStore上的信息撰糠,更改id就行
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://itunes.apple.com/lookup?id=你的APP的id"] encoding:NSUTF8StringEncoding error:nil];
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
//獲得上線版本號
NSString *version = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"version"];
NSString *updateInfo = [[[dic objectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"];
//獲得當前版本
NSString *currentVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleShortVersionString"];
dispatch_async(dispatch_get_main_queue(), ^{
//更新界面
if ( version &&![version isEqualToString:currentVersion]) {
//有新版本
NSString *message = [NSString stringWithFormat:@"有新版本發(fā)布啦!\n%@",updateInfo];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"溫馨提示" message:message delegate:self cancelButtonTitle:@"忽略"otherButtonTitles:@"前往更新",nil];
//此種寫法文字會居中顯示蔑赘,這樣視覺效果很不好,下列demo中已經(jīng)解決將alertview上的文字具有顯示 先關文章鏈接http://blog.csdn.net/bddzzw/article/details/52169261
[alertView show];
}else{
//已是最高版本
NSLog(@"已經(jīng)是最高版本");
}
});
});
}
/*根據(jù)被點擊按鈕的索引處理點擊事件--當被按鈕被點擊了這里做出一個反饋*/
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex ==1) {
NSString *url =@"你的APP在APPstore的網(wǎng)址";//
https://itunes.apple.com/cn/app/qq/id444934666?mt=8 QQ在APPstore的網(wǎng)址
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];
}
}
最后編輯于 :
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者