我的应用程序具有拨打电话的代码,但首先请求用户许可。如果可能的话,我需要在通话期间直接获得许可。
Future<void> _makePhoneCall() async {
if (Platform.isAndroid) {
final callPermissionStatus = await Permission.phone.request();
if (callPermissionStatus.isGranted) {
final String userPhone = contactPhone;
try {
const MethodChannel('caller').invokeMethod('makeCall', userPhone);
} on PlatformException catch (e) {
Fluttertoast.showToast(
msg: AppLocalizations.instance.translate("failedToCallTheNumber") +
("$contactPhone, ${e.message}"),
);
}
} else {
Fluttertoast.showToast(
msg: AppLocalizations.instance.translate("failedToCallTheNumber") +
("$contactPhone"),
);
}
} else if (Platform.isIOS) {
final callPermissionStatus = await Permission.phone.request();
if (callPermissionStatus.isGranted) {
final String userPhone = contactPhone;
try {
const MethodChannel('caller')
.invokeMethod('makeCall', userPhone);
} on PlatformException catch (e) {
Fluttertoast.showToast(
msg: AppLocalizations.instance.translate("failedToCallTheNumber") +
(" $contactPhone, ${e.message}"),
);
}
} else {
final String userPhone = contactPhone;
Fluttertoast.showToast(
msg: AppLocalizations.instance.translate("failedToCallTheNumber") +
(" $userPhone"),
);
}
}
}
此代码在 Android 上运行良好,但在 iOS 上没有对话框询问用户权限。我正在使用permission_handler:^11.3.1
但是在permission_handler的文档中:^11.3.1我找到了“电话”的描述 -
/// Permission for accessing the device's phone state (Android only). static const phone = PermissionWithService._(8);
除了“电话”之外,我应该使用什么来打开 iOS 的电话通话权限对话框?
或者我应该使用另一个库而不是permission_handler?
我的扑医生-
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale ru-UA)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.87.2)
[✓] VS Code (version 1.87.2)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!
如果您在线更换 -
final callPermissionStatus = await Permission.phone.request();
我还将这些行添加到 info.plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>needed to make phone calls</string>
</array>
<key>NSCallKitUsageDescription</key>
<string>Call access permission is required to make calls.</string>
<key>NSContactsUsageDescription</key>
<string>Permission to access contacts is required to make calls.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Permission to access the microphone is required to make calls.</string>
我不确定是否需要所有这些线路,我尝试添加所有内容以允许拨打电话。