Skip to content

Commit 8af8d91

Browse files
xtelincomravn-google
authored andcommitted
Fix url_launcher for iOS <10 (flutter#407)
1 parent fdb8312 commit 8af8d91

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

packages/url_launcher/ios/Classes/UrlLauncherPlugin.m

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,30 @@ - (BOOL)canLaunchURL:(NSString *)urlString {
9292
- (void)launchURL:(NSString *)urlString result:(FlutterResult)result {
9393
NSURL *url = [NSURL URLWithString:urlString];
9494
UIApplication *application = [UIApplication sharedApplication];
95-
[application openURL:url
96-
options:@{}
97-
completionHandler:^(BOOL success) {
98-
if (success) {
99-
result(nil);
100-
} else {
101-
result([FlutterError
102-
errorWithCode:@"Error"
103-
message:[NSString stringWithFormat:@"Error while launching %@", url]
104-
details:nil]);
105-
}
106-
}];
95+
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
96+
[application openURL:url
97+
options:@{}
98+
completionHandler:^(BOOL success) {
99+
if (success) {
100+
result(nil);
101+
} else {
102+
result([FlutterError
103+
errorWithCode:@"Error"
104+
message:[NSString stringWithFormat:@"Error while launching %@", url]
105+
details:nil]);
106+
}
107+
}];
108+
} else {
109+
BOOL success = [application openURL:url];
110+
if (success) {
111+
result(nil);
112+
} else {
113+
result([FlutterError
114+
errorWithCode:@"Error"
115+
message:[NSString stringWithFormat:@"Error while launching %@", url]
116+
details:nil]);
117+
}
118+
}
107119
}
108120

109121
- (void)launchURLInVC:(NSString *)urlString result:(FlutterResult)result {

0 commit comments

Comments
 (0)