Skip to content

Commit abb74d2

Browse files
Remove < iOS 11 fallback API calls in openSettings: (#1653)
* Remove < iOS 11 fallback API calls in openSettings: * Tests * CHANGELOG --------- Co-authored-by: TimHoogstrate <tim566@hotmail.com>
1 parent f4008db commit abb74d2

File tree

3 files changed

+25
-102
lines changed

3 files changed

+25
-102
lines changed

geolocator_apple/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.12
2+
3+
* Removed deprecated `-[UIApplication openURL:]` dead code.
4+
15
## 2.3.11
26

37
* Adds privacy manifest for macOS to the podspec.

geolocator_apple/example/ios/RunnerTests/GeolocatorPluginTests.m

+16-89
Original file line numberDiff line numberDiff line change
@@ -311,56 +311,20 @@ - (void)testRequestTemporaryFullAccuracyWithInvalidArgument {
311311
#pragma mark - Test open setting related methods
312312

313313
- (void)testOpenAppSettings {
314-
if (@available(iOS 10, *))
315-
{
316-
id mockApplication = OCMClassMock([UIApplication class]);
317-
OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
318-
options:@{}
319-
completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]);
320-
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
321-
322-
323-
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings"
324-
arguments:@{}];
325-
326-
XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."];
327-
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
328-
[plugin handleMethodCall:call result:^(id _Nullable result) {
329-
XCTAssertTrue(result);
330-
[expectation fulfill];
331-
}];
332-
333-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
334-
return;
335-
}
336-
337-
if (@available(iOS 8, *)) {
338-
id mockApplication = OCMClassMock([UIApplication class]);
339-
OCMStub([(UIApplication *)mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]).andReturn(YES);
340-
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
341-
342-
343-
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings"
344-
arguments:@{}];
345-
346-
XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."];
347-
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
348-
[plugin handleMethodCall:call result:^(id _Nullable result) {
349-
XCTAssertTrue(result);
350-
[expectation fulfill];
351-
}];
352-
353-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
354-
return;
355-
}
356-
314+
id mockApplication = OCMClassMock([UIApplication class]);
315+
OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
316+
options:@{}
317+
completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]);
318+
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
319+
320+
357321
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openAppSettings"
358322
arguments:@{}];
359323

360324
XCTestExpectation *expectation = [self expectationWithDescription:@"openAppSettings should return yes."];
361325
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
362326
[plugin handleMethodCall:call result:^(id _Nullable result) {
363-
XCTAssertFalse(result);
327+
XCTAssertTrue(result);
364328
[expectation fulfill];
365329
}];
366330

@@ -369,61 +333,24 @@ - (void)testOpenAppSettings {
369333
}
370334

371335
- (void)testOpenLocationSettings {
372-
if (@available(iOS 10, *))
373-
{
374-
id mockApplication = OCMClassMock([UIApplication class]);
375-
OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
376-
options:@{}
377-
completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]);
378-
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
379-
380-
381-
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings"
382-
arguments:@{}];
383-
384-
XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."];
385-
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
386-
[plugin handleMethodCall:call result:^(id _Nullable result) {
387-
XCTAssertTrue(result);
388-
[expectation fulfill];
389-
}];
390-
391-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
392-
return;
393-
}
394-
395-
if (@available(iOS 8, *)) {
396-
id mockApplication = OCMClassMock([UIApplication class]);
397-
OCMStub([(UIApplication *)mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]).andReturn(YES);
398-
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
399-
400-
401-
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings"
402-
arguments:@{}];
403-
404-
XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."];
405-
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
406-
[plugin handleMethodCall:call result:^(id _Nullable result) {
407-
XCTAssertTrue(result);
408-
[expectation fulfill];
409-
}];
410-
411-
[self waitForExpectationsWithTimeout:5.0 handler:nil];
412-
return;
413-
}
414-
336+
id mockApplication = OCMClassMock([UIApplication class]);
337+
OCMStub([mockApplication openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
338+
options:@{}
339+
completionHandler:([OCMArg invokeBlockWithArgs:@(YES), nil])]);
340+
OCMStub(ClassMethod([mockApplication sharedApplication])).andReturn(mockApplication);
341+
342+
415343
FlutterMethodCall *call = [FlutterMethodCall methodCallWithMethodName:@"openLocationSettings"
416344
arguments:@{}];
417345

418346
XCTestExpectation *expectation = [self expectationWithDescription:@"openLocationSettings should return yes."];
419347
GeolocatorPlugin *plugin = [[GeolocatorPlugin alloc] init];
420348
[plugin handleMethodCall:call result:^(id _Nullable result) {
421-
XCTAssertFalse(result);
349+
XCTAssertTrue(result);
422350
[expectation fulfill];
423351
}];
424352

425353
[self waitForExpectationsWithTimeout:5.0 handler:nil];
426-
return;
427354
}
428355

429356
@end

geolocator_apple/ios/Classes/GeolocatorPlugin.m

+5-13
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,12 @@ - (void)openSettings:(FlutterResult)result {
175175
BOOL success = [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
176176
result([[NSNumber alloc] initWithBool:success]);
177177
#else
178-
if (@available(iOS 10, *)) {
179-
[[UIApplication sharedApplication]
180-
openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
181-
options:[[NSDictionary alloc] init]
182-
completionHandler:^(BOOL success) {
183-
result([[NSNumber alloc] initWithBool:success]);
184-
}];
185-
} else if (@available(iOS 8.0, *)) {
186-
BOOL success = [[UIApplication sharedApplication]
187-
openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
178+
[[UIApplication sharedApplication]
179+
openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
180+
options:[[NSDictionary alloc] init]
181+
completionHandler:^(BOOL success) {
188182
result([[NSNumber alloc] initWithBool:success]);
189-
} else {
190-
result([[NSNumber alloc] initWithBool:NO]);
191-
}
183+
}];
192184
#endif
193185
}
194186
@end

0 commit comments

Comments
 (0)