From 4f7e1b14ddf0748513b1f6c297f1eccb03d57f8b Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 7 Mar 2025 15:33:28 -0800 Subject: [PATCH 1/3] Remove < iOS 11 fallback API calls in openSettings: --- .../ios/Classes/GeolocatorPlugin.m | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/geolocator_apple/ios/Classes/GeolocatorPlugin.m b/geolocator_apple/ios/Classes/GeolocatorPlugin.m index 0e3687a9..18655922 100644 --- a/geolocator_apple/ios/Classes/GeolocatorPlugin.m +++ b/geolocator_apple/ios/Classes/GeolocatorPlugin.m @@ -175,20 +175,12 @@ - (void)openSettings:(FlutterResult)result { BOOL success = [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]]; result([[NSNumber alloc] initWithBool:success]); #else - if (@available(iOS 10, *)) { - [[UIApplication sharedApplication] - openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] - options:[[NSDictionary alloc] init] - completionHandler:^(BOOL success) { - result([[NSNumber alloc] initWithBool:success]); - }]; - } else if (@available(iOS 8.0, *)) { - BOOL success = [[UIApplication sharedApplication] - openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; + [[UIApplication sharedApplication] + openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] + options:[[NSDictionary alloc] init] + completionHandler:^(BOOL success) { result([[NSNumber alloc] initWithBool:success]); - } else { - result([[NSNumber alloc] initWithBool:NO]); - } + }]; #endif } @end From e585389eee28402870c05c5de1c845bf368ea40f Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 7 Mar 2025 15:38:18 -0800 Subject: [PATCH 2/3] Tests --- .../ios/RunnerTests/GeolocatorPluginTests.m | 105 +++--------------- 1 file changed, 16 insertions(+), 89 deletions(-) diff --git a/geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m b/geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m index 72c5cfe1..3c661293 100644 --- a/geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m +++ b/geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m @@ -311,56 +311,20 @@ - (void)testRequestTemporaryFullAccuracyWithInvalidArgument { #pragma mark - Test open setting related methods - (void)testOpenAppSettings { - if (@available(iOS 10, *)) - { - id mockApplication = OCMClassMock([UIApplication class]); - OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] - options:@{} - completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]); - OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); - - - FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings" - arguments:@{}]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."]; - GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; - [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertTrue(result); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - return; - } - - if (@available(iOS 8, *)) { - id mockApplication = OCMClassMock([UIApplication class]); - OCMStub([(UIApplication *)mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]).andReturn(YES); - OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); - - - FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings" - arguments:@{}]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."]; - GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; - [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertTrue(result); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - return; - } - + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] + options:@{} + completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]); + OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); + + FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings" arguments:@{}]; XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."]; GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertFalse(result); + XCTAssertTrue(result); [expectation fulfill]; }]; @@ -369,61 +333,24 @@ - (void)testOpenAppSettings { } - (void)testOpenLocationSettings { - if (@available(iOS 10, *)) - { - id mockApplication = OCMClassMock([UIApplication class]); - OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] - options:@{} - completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]); - OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); - - - FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings" - arguments:@{}]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."]; - GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; - [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertTrue(result); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - return; - } - - if (@available(iOS 8, *)) { - id mockApplication = OCMClassMock([UIApplication class]); - OCMStub([(UIApplication *)mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]).andReturn(YES); - OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); - - - FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings" - arguments:@{}]; - - XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."]; - GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; - [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertTrue(result); - [expectation fulfill]; - }]; - - [self waitForExpectationsWithTimeout:5.0 handler:nil]; - return; - } - + id mockApplication = OCMClassMock([UIApplication class]); + OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] + options:@{} + completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]); + OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication); + + FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings" arguments:@{}]; XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."]; GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init]; [plugin handleMethodCall:call result:^(id _Nullable result) { - XCTAssertFalse(result); + XCTAssertTrue(result); [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:5.0 handler:nil]; - return; } @end From efffe3d4c12ccd1217268c3a5938413f55204a12 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 7 Mar 2025 15:47:52 -0800 Subject: [PATCH 3/3] CHANGELOG --- geolocator_apple/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/geolocator_apple/CHANGELOG.md b/geolocator_apple/CHANGELOG.md index c8cb80a2..cea95a80 100644 --- a/geolocator_apple/CHANGELOG.md +++ b/geolocator_apple/CHANGELOG.md @@ -1,3 +1,7 @@ +## NEXT + +* Removed deprecated `-[UIApplication openURL:]` dead code. + ## 2.3.10 * Updated dart sdk to sdk: `^3.5.0`