Skip to content

Instantly share code, notes, and snippets.

@victorchee
Created December 28, 2017 00:37
Show Gist options
  • Save victorchee/4a2e23e8a27980669745387676f9a43c to your computer and use it in GitHub Desktop.
Save victorchee/4a2e23e8a27980669745387676f9a43c to your computer and use it in GitHub Desktop.
Upgrade from itms service.
[[[NSURLSession sharedSession] downloadTaskWithURL:[NSURL URLWithString:@"https://alpha.migufun.com:38081/alpha/manifest.plist"] completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *plist = [[NSDictionary alloc] initWithContentsOfURL:location];
NSString *version = plist[@"items"][0][@"metadata"][@"bundle-version"];
NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
if ([version compare:currentVersion options:NSNumericSearch] == NSOrderedDescending) {
// 需要升级
NSURL *url = [NSURL URLWithString:@"itms-services://?action=download-manifest&url=https://alpha.migufun.com:38081/alpha/manifest.plist"];
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:url];
exit(0);
});
}
}] resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment