iOSアプリのアップグレードの注意とAppStoreのジャンプ
3448 ワード
今日はappアップグレードのヒントの流れを検討しましたが、簡単ではありません.シロたちが使えるように...
/**
* app
*
* PS:
* trackCensoredName = ;
* trackContentRating = ;
* trackId = ID;
* trackName = ;
* trackViewUrl = ;
* userRatingCount = ;
* userRatingCountForCurrentVersion = 1;
* version = ;
*/
-(void)judgeAPPVersion
{
// session
NSURLSession *session = [NSURLSession sharedSession];
NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com/lookup?id=1048992038"];
// URL task, block
NSURLSessionTask *task = [session dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"%@", [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]);
NSError *errorJs;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&errorJs];
NSDictionary *appInfo = (NSDictionary *)jsonObject;
NSArray *infoContent = [appInfo objectForKey:@"results"];
NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
NSLog(@" %@",version);
NSString *skipUrl = [[infoContent objectAtIndex:0] objectForKey:@"trackViewUrl"];
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];
NSLog(@" %@",currentVersion);
if (![version isEqualToString:currentVersion]) {
// appstore
[self skipAppStore:skipUrl];
}
}];
//
[task resume];
}
- (void)skipAppStore:(NSString*)strSkipUrl{
//
UIAlertController *alertDialog = [UIAlertController alertControllerWithTitle:@" " message:nil preferredStyle:UIAlertControllerStyleAlert];
//
UIAlertAction *laterAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// App
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:strSkipUrl]];
}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//
}];
// ( )
[alertDialog addAction:laterAction];
[alertDialog addAction:okAction];
//
[self presentViewController:alertDialog animated:YES completion:nil];
}