+(void)checkUpDataWithAPP_ID:(NSString*)APP_ID andResultBlock:(void(^)(BOOL result))resultBlock{
BOOL isUpdated = NO;
__block BOOL _isUpdate = isUpdated;
NSString *storeString = [NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%@", APP_ID];
NSURL *storeURL = [NSURL URLWithString:storeString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:storeURL];
[request setHTTPMethod:@"GET"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ( [data length] > 0 && !error ) { // Success
NSDictionary *appData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
NSArray *versionsInAppStore = [[appData valueForKey:@"results"] valueForKey:@"version"];
if (![versionsInAppStore count]) {
_isUpdate = NO;
resultBlock(NO);
}
else{
NSString *currentAppStoreVersion = [versionsInAppStore objectAtIndex:0];
NSString * myVersion = [Tool getVersion];
NSLog(@"app版本信息= %@,系统版本 = %@",currentAppStoreVersion,myVersion);
if ([myVersion compare:currentAppStoreVersion options:NSNumericSearch] == NSOrderedAscending){
//当前版本小
_isUpdate = YES;
resultBlock(YES);
}
else{
_isUpdate = NO;
resultBlock(NO);
}
}
});
}
}];
}