Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 5e36743

Browse files
committed
[ios] Add SDK version update checking/notification
1 parent 7e97012 commit 5e36743

File tree

7 files changed

+80
-0
lines changed

7 files changed

+80
-0
lines changed

platform/ios/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Mapbox welcomes participation and contributions from everyone. Please read [CONT
88

99
* The minimum deployment target for this SDK is now iOS 8. ([#8129](https://github.com/mapbox/mapbox-gl-native/pull/8129))
1010
* Added support for the Carthage dependency manager. See [our website](https://www.mapbox.com/ios-sdk/) for setup instructions. ([#8257](https://github.com/mapbox/mapbox-gl-native/pull/8257))
11+
* Added a simulator-only console notification to inform developers if there is a newer version of this SDK available. ([#8282](https://github.com/mapbox/mapbox-gl-native/pull/8282))
1112

1213
### Internationalization
1314

platform/ios/ios.xcodeproj/project.pbxproj

+12
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@
187187
7E016D851D9E890300A29A21 /* MGLPolygon+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */; };
188188
7E016D861D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; };
189189
7E016D871D9E890300A29A21 /* MGLPolygon+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */; };
190+
9620BB381E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */; };
191+
9620BB391E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */; };
192+
9620BB3A1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */; };
193+
9620BB3B1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */; };
190194
968F36B51E4D128D003A5522 /* MGLDistanceFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3557F7AE1E1D27D300CCA5E6 /* MGLDistanceFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; };
191195
96E027231E57C76E004B8E66 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 96E027251E57C76E004B8E66 /* Localizable.strings */; };
192196
DA00FC8E1D5EEB0D009AABC8 /* MGLAttributionInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = DA00FC8C1D5EEB0D009AABC8 /* MGLAttributionInfo.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -642,6 +646,8 @@
642646
7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = "<group>"; };
643647
7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = "<group>"; };
644648
7E016D831D9E890300A29A21 /* MGLPolygon+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolygon+MGLAdditions.m"; sourceTree = "<group>"; };
649+
9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLSDKUpdateChecker.h; sourceTree = "<group>"; };
650+
9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; path = MGLSDKUpdateChecker.mm; sourceTree = "<group>"; };
645651
9660916B1E5BBFD700A9A03B /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
646652
9660916C1E5BBFD900A9A03B /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
647653
9660916D1E5BBFDB00A9A03B /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Localizable.strings; sourceTree = "<group>"; };
@@ -1523,6 +1529,8 @@
15231529
DA8848471CBAFB9800AB86E3 /* MGLLocationManager.m */,
15241530
DA8848481CBAFB9800AB86E3 /* MGLMapboxEvents.h */,
15251531
DA8848491CBAFB9800AB86E3 /* MGLMapboxEvents.m */,
1532+
9620BB361E69FE1700705A1D /* MGLSDKUpdateChecker.h */,
1533+
9620BB371E69FE1700705A1D /* MGLSDKUpdateChecker.mm */,
15261534
);
15271535
name = Telemetry;
15281536
sourceTree = "<group>";
@@ -1618,6 +1626,7 @@
16181626
30E578171DAA85520050F07E /* UIImage+MGLAdditions.h in Headers */,
16191627
DAD1656C1CF41981001FF4B9 /* MGLFeature.h in Headers */,
16201628
40EDA1C01CFE0E0200D9EA68 /* MGLAnnotationContainerView.h in Headers */,
1629+
9620BB381E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */,
16211630
DA88484F1CBAFB9800AB86E3 /* MGLAnnotationImage_Private.h in Headers */,
16221631
1753ED421E53CE6F00A9FD90 /* MGLConversion.h in Headers */,
16231632
DA8847F21CBAFA5100AB86E3 /* MGLMapCamera.h in Headers */,
@@ -1679,6 +1688,7 @@
16791688
DA17BE311CC4BDAA00402C41 /* MGLMapView_Private.h in Headers */,
16801689
DABFB86C1CBE99E500D62B32 /* MGLTypes.h in Headers */,
16811690
DABFB8691CBE99E500D62B32 /* MGLShape.h in Headers */,
1691+
9620BB391E69FE1700705A1D /* MGLSDKUpdateChecker.h in Headers */,
16821692
3510FFEB1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */,
16831693
35E1A4D91D74336F007AA97F /* MGLValueEvaluator.h in Headers */,
16841694
7E016D7F1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */,
@@ -2095,6 +2105,7 @@
20952105
3510FFEC1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.mm in Sources */,
20962106
7E016D801D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m in Sources */,
20972107
DAED38651D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */,
2108+
9620BB3A1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */,
20982109
354B83981D2E873E005D9406 /* MGLUserLocationAnnotationView.m in Sources */,
20992110
DA88485D1CBAFB9800AB86E3 /* MGLFaux3DUserLocationAnnotationView.m in Sources */,
21002111
DAD165701CF41981001FF4B9 /* MGLFeature.mm in Sources */,
@@ -2172,6 +2183,7 @@
21722183
3510FFED1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.mm in Sources */,
21732184
7E016D811D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m in Sources */,
21742185
354B83991D2E873E005D9406 /* MGLUserLocationAnnotationView.m in Sources */,
2186+
9620BB3B1E69FE1700705A1D /* MGLSDKUpdateChecker.mm in Sources */,
21752187
DAA4E4221CBB730400178DFB /* MGLPointAnnotation.mm in Sources */,
21762188
DAED38661D62D0FC00D7640F /* NSURL+MGLAdditions.m in Sources */,
21772189
DAD165711CF41981001FF4B9 /* MGLFeature.mm in Sources */,

platform/ios/resources/Base.lproj/Localizable.strings

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
/* Action sheet title */
4444
"SDK_NAME" = "Mapbox iOS SDK";
4545

46+
/* Developer-only SDK update notification; {latest version, in format x.x.x} */
47+
"SDK_UPDATE_AVAILABLE" = "Mapbox iOS SDK version %@ is now available:";
48+
4649
/* Telemetry prompt message */
4750
"TELEMETRY_DISABLED_MSG" = "You can help make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.";
4851

platform/ios/resources/ja.lproj/Localizable.strings

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
/* Action sheet title */
4444
"SDK_NAME" = "Mapbox iOS SDK";
4545

46+
/* Developer-only SDK update notification; {latest version, in format x.x.x} */
47+
"SDK_UPDATE_AVAILABLE" = "現在Mapbox iOS SDK %1$@が入手できる:";
48+
4649
/* Telemetry prompt message */
4750
"TELEMETRY_DISABLED_MSG" = "You can help make OpenStreetMap and Mapbox maps better by contributing anonymous usage data.";
4851

platform/ios/src/MGLMapView.mm

+9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#import "MGLStyle_Private.h"
5656
#import "MGLStyleLayer_Private.h"
5757
#import "MGLMapboxEvents.h"
58+
#import "MGLSDKUpdateChecker.h"
5859
#import "MGLCompactCalloutView.h"
5960
#import "MGLAnnotationContainerView.h"
6061
#import "MGLAnnotationContainerView_Private.h"
@@ -347,6 +348,14 @@ - (instancetype)initWithCoder:(nonnull NSCoder *)decoder
347348
return self;
348349
}
349350

351+
+ (void)initialize
352+
{
353+
if (self == [MGLMapView self])
354+
{
355+
[MGLSDKUpdateChecker checkForUpdates];
356+
}
357+
}
358+
350359
+ (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingStyle
351360
{
352361
return [NSSet setWithObject:@"styleURL"];
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import <Foundation/Foundation.h>
2+
3+
#import "MGLFoundation.h"
4+
5+
NS_ASSUME_NONNULL_BEGIN
6+
7+
@interface MGLSDKUpdateChecker : NSObject
8+
9+
+ (void)checkForUpdates;
10+
11+
@end
12+
13+
NS_ASSUME_NONNULL_END
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#import "MGLSDKUpdateChecker.h"
2+
#import "NSBundle+MGLAdditions.h"
3+
#import "NSProcessInfo+MGLAdditions.h"
4+
5+
@implementation MGLSDKUpdateChecker
6+
7+
+ (void)checkForUpdates {
8+
#if TARGET_IPHONE_SIMULATOR
9+
// Abort if running in a playground.
10+
if ([[NSBundle mainBundle].bundleIdentifier hasPrefix:@"com.apple.dt.playground."] ||
11+
NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) {
12+
return;
13+
}
14+
15+
NSString *currentVersion = [NSBundle mgl_frameworkInfoDictionary][@"MGLSemanticVersionString"];
16+
17+
// Skip version check if weʼre doing gl-native development, as the framework
18+
// version is `1` until built for packaging.
19+
if ([currentVersion isEqualToString:@"1.0.0"]) {
20+
return;
21+
}
22+
23+
NSURL *url = [NSURL URLWithString:@"https://mapbox.s3.amazonaws.com/mapbox-gl-native/ios/latest_version"];
24+
[[NSURLSession.sharedSession dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
25+
if (error || ((NSHTTPURLResponse *)response).statusCode != 200) {
26+
return;
27+
}
28+
29+
NSString *latestVersion = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
30+
latestVersion = [latestVersion stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
31+
if (![currentVersion isEqualToString:latestVersion]) {
32+
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];
33+
NSLog(@"%@ https://github.com/mapbox/mapbox-gl-native/releases/tag/ios-v%@", updateAvailable, latestVersion);
34+
}
35+
}] resume];
36+
#endif
37+
}
38+
39+
@end

0 commit comments

Comments
 (0)