summaryrefslogtreecommitdiff
path: root/platform/ios/src/MGLSDKUpdateChecker.mm
blob: e40a31a22538bf0e056bb6d0f741d0bab441e392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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."]) {
        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://docs.mapbox.com/ios/maps/latest_version.txt"];
    [[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 Maps SDK for iOS 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