Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove < iOS 11 fallback API calls in openSettings: #1653

Merged
merged 4 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geolocator_apple/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.12

* Removed deprecated `-[UIApplication openURL:]` dead code.

## 2.3.11

* Adds privacy manifest for macOS to the podspec.
Expand Down
105 changes: 16 additions & 89 deletions geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];

Expand All @@ -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
18 changes: 5 additions & 13 deletions geolocator_apple/ios/Classes/GeolocatorPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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