方法一:
可以通过请求http://itunes.apple.com/cn/lookup?id=%@这个链接得到app在App Store上的信息(cn是因为只在中国,如果没有限制可去掉)
responseObject里包含两个参数resultCount = 1;results = ();results获得的是数组
- (void)checkVersion{
NSString *url = @"http://itunes.apple.com/cn/lookup?id=%@";
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/javascript", nil];
[manager POST:url parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSString *newVersion = responseObject[@"results"][0][@"version"];//获取版本号
NSLog(@"%@",responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
方法二:
第三方库iVersion,设置delegate
可通过pod 'iVersion'配置
更新提示(设置代理也可以)
[iVersion sharedInstance].applicationBundleID = [[NSBundle mainBundle] bundleIdentifier];
常用属性
[iVersion sharedInstance].appStoreCountry = @"cn";//指定国家
[[iVersion sharedInstance] setDelegate:self];//设置代理
[iVersion sharedInstance].updateAvailableTitle = @"版本更新";//设置标题
[iVersion sharedInstance].updatePriority=iVersionUpdatePriorityDefault;//提示框的样式(也可理解成按钮的显示,只有一个就是强更)
常用代理方法
- (BOOL)iVersionShouldCheckForNewVersion;//是否检测新版本
- (void)iVersionVersionCheckDidFailWithError:(NSError *)error;//检测失败
- (void)iVersionDidDetectNewVersion:(NSString *)version details:(NSString *)versionDetails;//检测到有更新版本
- (BOOL)iVersionShouldDisplayNewVersion:(NSString *)version details:(NSString *)versionDetails;//是否显示默认更新界面,yes显示,no不显示
- (void)iVersionUserDidAttemptToDownloadUpdate:(NSString *)version;//点击下载
- (void)iVersionUserDidRequestReminderForUpdate:(NSString *)version;//点击下一次提醒
- (void)iVersionUserDidIgnoreUpdate:(NSString *)version;//点击忽视更新
- (BOOL)iVersionShouldOpenAppStore;//打开App Store