From c7d53676d0dcbc72d71d921e385c656087b788a5 Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Wed, 27 Mar 2019 09:58:41 -0400 Subject: [ios, core] Updates project for iOS SDK 12.2 / Always use vendored optional (#14241) --- platform/darwin/src/NSBundle+MGLAdditions.m | 7 ++++++- platform/darwin/test/MGLAttributionInfoTests.m | 15 +++++++++++++-- platform/darwin/test/MGLOfflineStorageTests.mm | 9 ++++----- .../Annotation Tests/MGLAnnotationViewIntegrationTests.m | 1 - .../ios/Integration Tests/MGLCameraTransitionTests.mm | 2 +- platform/ios/ios.xcodeproj/project.pbxproj | 6 +++--- platform/ios/src/MGLMapView.mm | 13 +++++++++---- 7 files changed, 36 insertions(+), 17 deletions(-) (limited to 'platform') diff --git a/platform/darwin/src/NSBundle+MGLAdditions.m b/platform/darwin/src/NSBundle+MGLAdditions.m index d472e40b1f..da70a95373 100644 --- a/platform/darwin/src/NSBundle+MGLAdditions.m +++ b/platform/darwin/src/NSBundle+MGLAdditions.m @@ -35,10 +35,15 @@ const MGLExceptionName MGLBundleNotFoundException = @"MGLBundleNotFoundException + (nullable NSString *)mgl_applicationBundleIdentifier { NSString *bundleIdentifier = [NSBundle mainBundle].bundleIdentifier; + +#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && (__IPHONE_OS_VERSION_MAX_ALLOWED < 120200)) || \ + (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED < 101404)) + // Before SDK 12.2 (bundled with Xcode 10.2): There’s no main bundle identifier when running in a unit test bundle. + // 12.2 and after: the above bundle identifier is: com.apple.dt.xctest.tool if (!bundleIdentifier) { - // There’s no main bundle identifier when running in a unit test bundle. bundleIdentifier = [NSBundle bundleForClass:[MGLAccountManager class]].bundleIdentifier; } +#endif return bundleIdentifier; } diff --git a/platform/darwin/test/MGLAttributionInfoTests.m b/platform/darwin/test/MGLAttributionInfoTests.m index 48779f3407..b6f053a8af 100644 --- a/platform/darwin/test/MGLAttributionInfoTests.m +++ b/platform/darwin/test/MGLAttributionInfoTests.m @@ -55,10 +55,21 @@ XCTAssertEqualObjects(infos[3].URL, [NSURL URLWithString:@"https://apps.mapbox.com/feedback/"]); XCTAssertTrue(infos[3].feedbackLink); NSURL *styleURL = [MGLStyle satelliteStreetsStyleURLWithVersion:99]; + +#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120200) || \ + (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101404) + NSString *bundleId = @"com.apple.dt.xctest.tool"; +#else + NSString *bundleId = @"com.mapbox.Mapbox"; +#endif + + NSString *urlString = [NSString stringWithFormat:@"https://apps.mapbox.com/feedback/?referrer=%@#/77.63680/12.98108/14.00/0.0/0", bundleId]; XCTAssertEqualObjects([infos[3] feedbackURLAtCenterCoordinate:mapbox zoomLevel:14], - [NSURL URLWithString:@"https://apps.mapbox.com/feedback/?referrer=com.mapbox.Mapbox#/77.63680/12.98108/14.00/0.0/0"]); + [NSURL URLWithString:urlString]); + + urlString = [NSString stringWithFormat:@"https://apps.mapbox.com/feedback/?referrer=%@&owner=mapbox&id=satellite-streets-v99&access_token=pk.feedcafedeadbeefbadebede&map_sdk_version=1.0.0#/77.63680/12.98108/3.14/90.9/13", bundleId]; XCTAssertEqualObjects([infos[3] feedbackURLForStyleURL:styleURL atCenterCoordinate:mapbox zoomLevel:3.14159 direction:90.9 pitch:12.5], - [NSURL URLWithString:@"https://apps.mapbox.com/feedback/?referrer=com.mapbox.Mapbox&owner=mapbox&id=satellite-streets-v99&access_token=pk.feedcafedeadbeefbadebede&map_sdk_version=1.0.0#/77.63680/12.98108/3.14/90.9/13"]); + [NSURL URLWithString:urlString]); } - (void)testStyle { diff --git a/platform/darwin/test/MGLOfflineStorageTests.mm b/platform/darwin/test/MGLOfflineStorageTests.mm index 7f0ead7cab..86dc28eb04 100644 --- a/platform/darwin/test/MGLOfflineStorageTests.mm +++ b/platform/darwin/test/MGLOfflineStorageTests.mm @@ -1,6 +1,7 @@ #import #import "MGLOfflineStorage_Private.h" +#import "NSBundle+MGLAdditions.h" #import "NSDate+MGLAdditions.h" #import @@ -10,7 +11,6 @@ #pragma clang diagnostic ignored "-Wshadow" @interface MGLOfflineStorageTests : XCTestCase - @end @implementation MGLOfflineStorageTests @@ -21,8 +21,7 @@ appropriateForURL:nil create:NO error:nil]; - // Unit tests don't use the main bundle; use com.mapbox.ios.sdk instead. - NSString *bundleIdentifier = [NSBundle bundleForClass:[MGLMapView class]].bundleIdentifier; + NSString *bundleIdentifier = [NSBundle mgl_applicationBundleIdentifier]; cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier]; cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@".mapbox"]; XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:cacheDirectoryURL.path], @"Cache subdirectory should exist."); @@ -208,8 +207,8 @@ appropriateForURL:nil create:NO error:nil]; - // Unit tests don't use the main bundle; use com.mapbox.ios.sdk instead. - NSString *bundleIdentifier = [NSBundle bundleForClass:[MGLMapView class]].bundleIdentifier; + // As of iOS SDK 12.2 unit tests now have a bundle id: com.apple.dt.xctest.tool + NSString *bundleIdentifier = [NSBundle mgl_applicationBundleIdentifier]; cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:bundleIdentifier]; cacheDirectoryURL = [cacheDirectoryURL URLByAppendingPathComponent:@".mapbox"]; XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:cacheDirectoryURL.path], @"Cache subdirectory should exist."); diff --git a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m index 7ec45de072..0b32df55b4 100644 --- a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m +++ b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m @@ -405,7 +405,6 @@ static const CGFloat kAnnotationScale = 0.125f; NSString * const MGLTestAnnotationReuseIdentifer = @"MGLTestAnnotationReuseIdentifer"; - CGFloat epsilon = 0.0000001; CGSize size = self.mapView.bounds.size; CGSize annotationSize = CGSizeMake(40.0, 40.0); diff --git a/platform/ios/Integration Tests/MGLCameraTransitionTests.mm b/platform/ios/Integration Tests/MGLCameraTransitionTests.mm index e422c46cf4..60d5fc6c9a 100644 --- a/platform/ios/Integration Tests/MGLCameraTransitionTests.mm +++ b/platform/ios/Integration Tests/MGLCameraTransitionTests.mm @@ -277,7 +277,7 @@ // Now set another coordinate. MGLMapCamera *camera = [MGLMapCamera cameraLookingAtCenterCoordinate:target2 - fromDistance:altitude + altitude:altitude pitch:0.0 heading:0.0]; diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index a514f4a017..5122a60b11 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -3677,7 +3677,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Integration Tests/integration-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Integration Test Harness.app/Integration Test Harness"; }; @@ -3707,7 +3707,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.integration-tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Integration Tests/integration-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Integration Test Harness.app/Integration Test Harness"; }; @@ -3992,7 +3992,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.mapbox.integration-tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Integration Tests/integration-Bridging-Header.h"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Integration Test Harness.app/Integration Test Harness"; }; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 50e022013b..eab690b854 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -2512,10 +2512,15 @@ public: { MGLLogInfo(@"Resetting the map to the current style’s default viewport."); auto camera = self.mbglMap.getStyle().getDefaultCamera(); - CGFloat pitch = *camera.pitch; - CLLocationDirection heading = mbgl::util::wrap(*camera.bearing, 0., 360.); - CLLocationDistance altitude = MGLAltitudeForZoomLevel(*camera.zoom, pitch, 0, self.frame.size); - self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(*camera.center) + + double pitch = camera.pitch ? *camera.pitch : 0.0; + double bearing = camera.bearing ? *camera.bearing : 0.0; + double zoom = camera.zoom ? *camera.zoom : 0.0; + mbgl::LatLng center = camera.center ? *camera.center : mbgl::LatLng(); + + CLLocationDirection heading = mbgl::util::wrap(bearing, 0., 360.); + CLLocationDistance altitude = MGLAltitudeForZoomLevel(zoom, pitch, 0, self.frame.size); + self.camera = [MGLMapCamera cameraLookingAtCenterCoordinate:MGLLocationCoordinate2DFromLatLng(center) altitude:altitude pitch:pitch heading:heading]; -- cgit v1.2.1