-(IBAction)checkVersion:(id)sender
{
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
CFShow(CFBridgingRetain(infoDic));
NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
NSLog(@"%@",appVersion);
[self getsAppInfo:^(NSMutableDictionary *items, NSError *error)
{
NSString *version=[items objectForKey:@"version"];
NSLog(@"%@,,,%@",appVersion,version);
if (![version isEqualToString:appVersion]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
[alert show];
}
}];
}
-(void)getsAppInfo:(void (^)(NSMutableDictionary *list, NSError *error))block
{
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/lookup?id=571873981"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
NSMutableArray *infolist = [JSON objectForKey:@"results"];
if (block){
block([NSMutableDictionary dictionaryWithDictionary:[infolist lastObject]], nil);
}
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
{
if (block) {
block([NSMutableDictionary dictionary], error);
}
}];
[operation start];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1)
{
NSString *iTunesLink = @"http://itunes.apple.com/cn/app/id571873981";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
}
}