diff --git a/geolocator_apple/CHANGELOG.md b/geolocator_apple/CHANGELOG.md index 4aef1d51..d2c0786d 100644 --- a/geolocator_apple/CHANGELOG.md +++ b/geolocator_apple/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.12 + +* Removed deprecated `-[UIApplication openURL:]` dead code. + ## 2.3.11 * Adds privacy manifest for macOS to the podspec. 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 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