在flutter中在iOS设备上运行permission_handler时出错

问题描述 投票:0回答:1

我正在使用

permission_handler
请求 Flutter 应用程序中本地通知的权限。然而,当我在 iOS 设备上运行该应用程序时,它崩溃了。

import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:permission_handler/permission_handler.dart';

Future<void> requestNotificationPermission() async {
  if (await Permission.notification.isDenied) {
    await Permission.notification.request();
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await requestNotificationPermission(); // Request permission on app launch

  runApp(MyApp());
}

我在ios设备上运行时遇到此错误:

    [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception:     MissingPluginException(No implementation found for method checkPermissionStatus on channel     flutter.baseflow.com/permissions/methods)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
    <asynchronous suspension>
    #1      MethodChannelPermissionHandler.checkPermissionStatus  (package:permission_handler_platform_interface/src/method_channel/method_channel_permission_handler .dart:17:20)
    <asynchronous suspension>
    #2      requestNotificationPermission (package:bmicalculator/main.dart:11:16)
    <asynchronous suspension>
    #3      main (package:bmicalculator/main.dart:21:3)
    <asynchronous suspension>
    the Dart compiler exited unexpectedly.

尝试跑步

flutter clean
flutter pub get
flutter run
。将
UIBackgroundModes
NSUserNotificationUsageDescription
添加到 Info.plist。

通过添加

pubspec.yaml
更改了
permission_handler

有人可以帮忙吗?

ios flutter flutter-local-notification
1个回答
0
投票
pub upgrade 
flutter clean, flutter pub get
cd IOS, pod install after 
© www.soinside.com 2019 - 2024. All rights reserved.