iOS App检测更新

// 1. 获取App的版本

NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];

NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

// 2. 获取苹果服务器端App 版本号

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

[manager POST:@"https://itunes.apple.com/lookup?id=Your App Id" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

NSArray *array = responseObject[@"results"];

NSDictionary *dict = [array lastObject];

NSString *appStoreVersion = dict[@"version"]; // 苹果服务器端版本号

if (![currentVersion isEqualToString:appStoreVersion]) {

//3. 如果App的版本号与苹果服务器端App 版本号不一致, 则认为App 非最新版本

NSLog(@"有新版本可供下载");

}

} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {

}];

// 备注: 如果App 只在中国上架, 则请求网址:https://itunes.apple.com/cn/lookup?id=Your App Id

你可能感兴趣的:(iOS App检测更新)