版本更新提示是app必备功能,它可以有效提示用户更新。常用的更新提示无非有两种。一种是从苹果api获取版本信息,提示用户更新;另外一种则是通过自定义接口实现。下面我们主要就谈谈apple的api获取版本信息并提示更新。
方法很简单,直接使用调用NSURLSession发送网络请求。如下
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/CN/lookup?id=%@",appID]];
[[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (error == nil && data != nil && data.length > 0) {
NSDictionary *respDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if (success) {
success(respDict);
}
}
});
}] resume];
打印一下respect:

我们要用的有效信息有version,artistViewUrl和relseaseNotes,接下来我们要做的就是讲获取到的version和本地plist文件的版本号进行比较。在这之前我们可以将获取到的字典转化为包含有效信息的类进行传递。这里就不赘述了。
这里提供两种提示方法,一种是系统提示框,一种你可以自定义提示框。
[checkVersionManager checkNewEditionWithAppID:@"1177904945" ctrl:self];
[checkVersionManager checkNewEditionWithAppID:@"1177904945" CustomAlert:^(AppleStoreModel *appInfo) {
}];

代码文件:github下载
网友评论