-(void)checkVersion
{
NSString *myAppCurrentVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
//NSString *myAppCurrentBuild = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
// Asynchronously query iTunes AppStore for publically available version
NSString *storeString = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%d", 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(), ^{
// All versions that have been uploaded to the AppStore
NSArray *versionsInAppStore = [[appData valueForKey:@"results"] valueForKey:@"version"];
if ( ![versionsInAppStore count] ) { // No versions of app in AppStore
return;
} else {
//[[NSNotificationCenter defaultCenter]postNotificationName:@"checkCurrentVersion" object:currentAppStoreVersion];
NSString *currentAppStoreVersion = [versionsInAppStore objectAtIndex:0];
NSLog(@"currentAppStoreVersion = %@", currentAppStoreVersion);
if ([myAppCurrentVersion compare:currentAppStoreVersion options:NSNumericSearch] == NSOrderedAscending) {
// Upgrade notification.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"RPS Upgrade Notification"
message:[NSString stringWithFormat:@"新版本 %@ 可用,請更新版本。", currentAppStoreVersion]
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"更新", nil];
[alertView show];
} else {
// Current installed version is the newest public version or newer
//[[NSNotificationCenter defaultCenter]postNotificationName:@"checkCurrentVersion" object:@""];
}
}
});
}
}];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%d", APP_ID]]];
}
留言列表