- (void)checkUpdateVersion {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSString *url = @"https://itunes.apple.com/lookup?id=yourAppleId";
NSString *encodingUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[manager GET:encodingUrl parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
// App Store最新版本号
NSString *latestVersion = resultDict[@"results"][0][@"version"];
// 本地当前版本号
NSString *currentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *latestVersionInt = [latestVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
NSString *currentVersionInt = [currentVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
if (latestVersionInt.integerValue > currentVersionInt.integerValue) {
// 弹出更新弹框
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
网友评论