美文网首页
iOS 版本更新

iOS 版本更新

作者: magicL1 | 来源:发表于2017-10-30 15:11 被阅读0次

1.获取本地版本信息

2.获取App Store版本信息

3.新旧版本对比

代码:

请求的基类中获取App Store版本信息:

+ (void)checkVersionSuccess:(HttpCheckSuccess)success failure:(HttpFailureStr)failure

{

NSString *vv = [NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];

NSString * _oldVersionValue = [vv substringFromIndex:8];    //当前Xcode中版本

//KAppId App Store上应用的ID

NSString *url_string = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@", KAppId];

[[AppNetworking shareManager] GET:url_string parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {

} success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

NSArray *appInfoItems = [responseObject objectForKey:@"results"];

if ([appInfoItems count] > 0) {

NSDictionary *appInfoDict = [appInfoItems objectAtIndex:0];

NSLog(@"appInfoDict: %@", appInfoDict);

//App Store线上版本

NSString *sysValue = [appInfoDict objectForKey:@"version"];

NSString *newSys = [sysValue stringByReplacingOccurrencesOfString:@"." withString:@""]; 

NSString *newOld = [_oldVersionValue stringByReplacingOccurrencesOfString:@"." withString:@""];

if (success) {

//新版本信息大于旧版本信息——>有更新。

success(sysValue,newOld.integerValue < newSys.integerValue);

}

}else

{

if (failure) {

failure(_oldVersionValue);

}

}

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

NSLog(@"%@",error.localizedDescription);

if (error.code==3840) {

if (failure) {

failure(@"网络开小差啦 请稍后再试");

}

return ;

}

if (failure) {

failure(_oldVersionValue);

}

}];

}

AppDelegate中调用上述方法进行提示功能。

- (void)applicationWillEnterForeground:(UIApplication *)application

{

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"updateMessage"]) return;

[AppNetworking checkVersionSuccess:^(NSString *version, BOOL update) {

if (update) {

NSString *msg = [NSString stringWithFormat:@"为不影响正常使用,请到App Store更新模块下载最新版本%@",version];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新提醒" message:msg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];

[alert show];

}

} failure:^(NSString *errorMessage) {

}];

}

//提示更新

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"updateMessage"];

[[NSUserDefaults standardUserDefaults] synchronize];

if (buttonIndex == 1) return;

NSString *appstoreUrlString = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",KAppId];

NSURL * url = [NSURL URLWithString:appstoreUrlString];

if ([[UIApplication sharedApplication] canOpenURL:url])

{

[[UIApplication sharedApplication] openURL:url];

}

else

{

NSLog(@"url can not open");

}

}

相关文章

  • iOS版本更新

    iOS APP版本 更新

  • iOS 上传AppStore 被拒汇总

    (1)、苹果要求版本更新必须使用iOS版本更新内置更新机制。 4. Design: Preamble Design...

  • iOS版本更新

    1、获取当前版本 NSString *current_version = [[[NSBundle mainBund...

  • iOS 版本更新

    获取本机版本号 NSDictionary *localDic = [[NSBundle mainBundle] i...

  • iOS版本更新

    版本更新 #pragma mark -检查版本更新 - (void)checkNewVersion { // NS...

  • iOS 版本更新

    众所周知苹果拒绝任何带有版本更新的提示出现在页面中,因此我们通过接口获取,处理是否显示更新提示。 1.判断版本号 ...

  • iOS 版本更新

    1.获取本地版本信息 2.获取App Store版本信息 3.新旧版本对比 代码: 请求的基类中获取App Sto...

  • iOS版本更新

    最近,应项目需求,简单写了一个版本更新的提示,有需要的码友可以去下载看看,实现起来比较简单。 效果图 首先是请求a...

  • iOS版本更新

    一、获取app线上版本苹果提供网址:https://itunes.apple.com/lookup网址所需参数:i...

  • iOS 版本更新

    今天公司要给APP加上“检查更新”这个服务,因为在上一家公司做过,所以没花太多时间就完成了。不过还是看以前公司的代...

网友评论

      本文标题:iOS 版本更新

      本文链接:https://www.haomeiwen.com/subject/ydnppxtx.html