admin管理员组文章数量:1410682
I am trying to launch URLs, emails, phone calls, and SMS using the url_launcher package in Flutter. While it works fine on Android, it does not work as expected on iOS when using LaunchMode.externalApplication.
- Flutter : 3.19.6
- url_launcher: 6.3.1
I have a custom function to handle different URL types:
import 'package:url_launcher/url_launcher.dart';
Future<bool> openLink({
required String url,
LaunchMode? mode,
required PrefixLauncher prefix,
bool showMsg = true,
WebViewConfiguration? webViewConfiguration,
}) async {
try {
var baseUrl = '';
switch (prefix) {
case PrefixLauncher.url:
baseUrl = 'https://$url';
break;
case PrefixLauncher.email:
baseUrl = 'mailto:$url';
break;
case PrefixLauncher.call:
baseUrl = 'tel:$url'.replaceAll(" ", "");
break;
case PrefixLauncher.message:
baseUrl = 'sms:$url';
break;
default:
baseUrl = url;
break;
}
Uri uri = Uri.parse(baseUrl);
if (await canLaunchUrl(uri)) {
if (!await launchUrl(
uri,
mode: mode ?? LaunchMode.externalApplication, // Default mode
)) {
if (showMsg) showToast('something_wrong'.tr());
Log.error('Could not launch : $url');
return false;
} else {
return true;
}
}
return false;
} on Exception catch (e) {
Log.error('Error: $e');
return false;
}
}
I have added the required schemes in my ios/Runner/Info.plist file:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>https</string>
<string>http</string>
<string>mailto</string>
<string>tel</string>
<string>sms</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
The app should open URLs, email clients, phone dialer, and SMS apps externally on iOS when using LaunchMode.externalApplication.
However, on iOS, calling openLink() with LaunchMode.externalApplication does not launch the external app. No error message is displayed. It works fine on Android.
本文标签: flutterlaunchUrl Not Working with LaunchModeexternalApplication on iOSStack Overflow
版权声明:本文标题:flutter - launchUrl Not Working with LaunchMode.externalApplication on iOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744990025a2636326.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论