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
Changes from 3 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 @@
## NEXT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to bump the version if you prefer, up to you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmagman would be great. Thanks. Since I have not released 2.3.10 yet, I prefer it to be added to 2.3.10, since that is just a relative minor (update) release.


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

## 2.3.10

* Updated dart sdk to sdk: `^3.5.0`
105 changes: 16 additions & 89 deletions geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m
Original file line number Diff line number Diff line change
@@ -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
18 changes: 5 additions & 13 deletions geolocator_apple/ios/Classes/GeolocatorPlugin.m
Original file line number Diff line number Diff line change
@@ -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