/**
检测版本更新
@param appId AppID
*/
- (void)testVersionUpdate:(NSString *)appId{
NSString *url = [NSString stringWithFormat:@"https://itunes.apple.com/lookup?id=%@",appId];//这里的ID是APPID
NSString *urlStr = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = [AFSecurityPolicy defaultPolicy];
manager.securityPolicy.allowInvalidCertificates = YES;//忽略https证书
manager.securityPolicy.validatesDomainName = NO;//是否验证域名
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
DLog(@"App=====%@",dict);
NSMutableArray *array = dict[@"results"];
NSString *str;
for (NSDictionary *dic in array) {
str = dic[@"version"];
}
// 获取当前的版本
NSDictionary *infoDict = [[NSBundle mainBundle]infoDictionary];
NSString *currentVersion = [infoDict objectForKey:@"CFBundleShortVersionString"];
// NSLog(@"======%@",infoDict);
NSArray * bundleArray = [currentVersion componentsSeparatedByString:@"."];
NSString *bundleStr = @"";
for (int i = 0; i<bundleArray.count; i++) {
if (i == 0) {
bundleStr = [NSString stringWithFormat:@"%@.",bundleArray[0]];
}else{
bundleStr = [NSString stringWithFormat:@"%@%@",bundleStr,bundleArray[i]];
}
}
CGFloat bundleVersion = [bundleStr floatValue];
if ([str isEqualToString:@"(null)"]||str.length == 0 || [str isEqualToString:@"null"] ) {
NSLog(@"====%f",bundleVersion);
}else{
NSArray * appArray = [str componentsSeparatedByString:@"."];
NSString *appStr = @"";
for (int i = 0; i<appArray.count; i++) {
if (i == 0) {
appStr = [NSString stringWithFormat:@"%@.",appArray[0]];
}else{
appStr = [NSString stringWithFormat:@"%@%@",appStr,appArray[i]];
}
}
CGFloat appVersion = [appStr floatValue];
DLog(@"当前版本====%f Appstroe版本====%f",bundleVersion,appVersion);
if (appVersion > bundleVersion) {
UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"有新的版本更新,是否前往更新?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
[alertVc dismissViewControllerAnimated:YES completion:nil];
}];
[alertVc addAction:cancelAction];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"前往" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//跳转到AppStore,该App下载界面
NSString * trackViewUrl = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@?mt=8", appId];
NSURL *url = [NSURL URLWithString:trackViewUrl];
[[UIApplication sharedApplication] openURL:url];
}];
[alertVc addAction:okAction];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:alertVc animated:YES completion:nil];
}
}
} failure:nil];
}
iOS 检测版本更新
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...