diff options
author | Jason Wray <jason@mapbox.com> | 2017-03-03 13:27:28 -0800 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2017-03-07 10:43:08 -0800 |
commit | 5e36743ef76dc590be45dddf376139c35ea145a4 (patch) | |
tree | 1f3aace7be08c2ea74846a52031e139c94878182 /platform/ios/src/MGLSDKUpdateChecker.mm | |
parent | 7e9701283f96bfcce3a56a3af4c8fe9154f02b61 (diff) | |
download | qtlocation-mapboxgl-5e36743ef76dc590be45dddf376139c35ea145a4.tar.gz |
[ios] Add SDK version update checking/notification
Diffstat (limited to 'platform/ios/src/MGLSDKUpdateChecker.mm')
-rw-r--r-- | platform/ios/src/MGLSDKUpdateChecker.mm | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/platform/ios/src/MGLSDKUpdateChecker.mm b/platform/ios/src/MGLSDKUpdateChecker.mm new file mode 100644 index 0000000000..a342a68c0d --- /dev/null +++ b/platform/ios/src/MGLSDKUpdateChecker.mm @@ -0,0 +1,39 @@ +#import "MGLSDKUpdateChecker.h" +#import "NSBundle+MGLAdditions.h" +#import "NSProcessInfo+MGLAdditions.h" + +@implementation MGLSDKUpdateChecker + ++ (void)checkForUpdates { +#if TARGET_IPHONE_SIMULATOR + // Abort if running in a playground. + if ([[NSBundle mainBundle].bundleIdentifier hasPrefix:@"com.apple.dt.playground."] || + NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { + return; + } + + NSString *currentVersion = [NSBundle mgl_frameworkInfoDictionary][@"MGLSemanticVersionString"]; + + // Skip version check if weʼre doing gl-native development, as the framework + // version is `1` until built for packaging. + if ([currentVersion isEqualToString:@"1.0.0"]) { + return; + } + + NSURL *url = [NSURL URLWithString:@"https://mapbox.s3.amazonaws.com/mapbox-gl-native/ios/latest_version"]; + [[NSURLSession.sharedSession dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (error || ((NSHTTPURLResponse *)response).statusCode != 200) { + return; + } + + NSString *latestVersion = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + latestVersion = [latestVersion stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + if (![currentVersion isEqualToString:latestVersion]) { + NSString *updateAvailable = [NSString stringWithFormat:NSLocalizedStringWithDefaultValue(@"SDK_UPDATE_AVAILABLE", nil, nil, @"Mapbox iOS SDK version %@ is now available:", @"Developer-only SDK update notification; {latest version, in format x.x.x}"), latestVersion]; + NSLog(@"%@ https://github.com/mapbox/mapbox-gl-native/releases/tag/ios-v%@", updateAvailable, latestVersion); + } + }] resume]; +#endif +} + +@end |