日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS检测更新功能

發(fā)布時間:2025/5/22 编程问答 76 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS检测更新功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標準>>>

//
// ?LBViewController.m
// ?LiveBroadcast
//
// ?Created by gz on 16/9/14.
// ?Copyright ? 2016年
//

#import "LBViewController.h"


#define kAPP_URL @"http://itunes.apple.com/lookup?id="
#define kAppID @"112125"

[@interface](https://my.oschina.net/u/996807) LBViewController () {
? ? NSString * _trackViewUrl;
}

[@end](https://my.oschina.net/u/567204)

@implementation LBViewController

- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
- (void)checkUpdateApp {
? ? NSError *error;
? ? //kAPP_URL : http://itunes.apple.com/lookup?id=
? ? //kAppId : 在iTunes connect上申請的APP ID
? ? NSString *urlStr = [NSString stringWithFormat:@"%@%@", kAPP_URL, kAppID];
? ? NSURL *url = [NSURL URLWithString:urlStr];
? ? NSURLRequest *request = [NSURLRequest requestWithURL:url];
? ? NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
? ??
? ? NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?options:NSJSONReadingAllowFragments
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?error:&error];
// ? ?NSDictionary *appInfoDict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
? ??
? ? if (error) {
? ? ? ? NSLog(@"%@", error.description);
? ? ? ? return;
? ? }
? ??
? ? NSArray *resultArray = [appInfoDict objectForKey:@"results"];
? ??
? ? if (![resultArray count]) {
? ? ? ? NSLog(@"error : resultArray == nil");
? ? ? ? return;
? ? }
? ??
? ? NSDictionary *infoDict = [resultArray objectAtIndex:0];
? ? //獲取服務器上應用的最新版本號
? ? NSString *appleV = infoDict[@"version"];
? ? NSString *aV = [appleV copy];
? ??
? ? NSString *trackName = infoDict[@"trackName"];
? ??
? ? _trackViewUrl = infoDict[@"trackViewUrl"];
? ??
? ? //獲取當前設備中應用的版本號
? ? NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
? ? NSString *cV = [infoDic objectForKey:@"CFBundleShortVersionString"];
? ??
? ? cV = [cV stringByReplacingOccurrencesOfString:@"." withString:@""];
? ? aV = [aV stringByReplacingOccurrencesOfString:@"." withString:@""];
? ??
? ? NSInteger length = MIN(cV.length, aV.length);

? ? cV = [cV substringToIndex:length];
? ? aV = [aV substringToIndex:length];

? ? CGFloat updateVersion = [aV doubleValue];
? ? CGFloat currentVersion = [cV doubleValue];
? ? //判斷兩個版本是否相同
? ? if (currentVersion <= updateVersion) {
? ? ? ? UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@",trackName] message:[NSString stringWithFormat:@"發(fā)現(xiàn)新版本(%@),是否更新", appleV] preferredStyle:UIAlertControllerStyleAlert];
? ? ? ? UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
? ? ? ? }];
? ? ? ? [alertController addAction:cancelAction];
? ? ? ? UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"升級" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
? ? ? ? ? ? [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_trackViewUrl]];
? ? ? ? }];
? ? ? ? [alertController addAction:sureAction];
? ? ? ? [self presentViewController:alertController animated:YES completion:nil];
? ? ? ??
? ? } else { ?//版本號和app store上的一致
? ? }
}

@end

轉載于:https://my.oschina.net/gdxz111/blog/746902

總結

以上是生活随笔為你收集整理的iOS检测更新功能的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。