IOS中的MissingPluginException(在channel plugins.flutter.io/firebase_messaging上未找到方法requestNotificationPermissions的实现)

时间:2020-06-25 10:19:51

标签: ios flutter firebase-cloud-messaging

在IOS模拟器中运行我的应用程序时,出现此错误:有人知道原因吗?

顺便说一句,它适用于Android。

enter image description here

AppDelegate.swift

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

获得许可的代码:

  getIOSPermission() {
    _firebaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(alert: true, badge: true, sound: true));
    _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
      print("Settings registered:$settings");
    });
  }


void requestIOSPermissions() {
    flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<
            IOSFlutterLocalNotificationsPlugin>()
        ?.requestPermissions(
          alert: true,
          badge: true,
          sound: true,
        );
  }
     if (Platform.isIOS) {
      getIOSPermission();
      requestIOSPermissions();
      connector.requestNotificationPermissions();
    }

1 个答案:

答案 0 :(得分:0)

我假设FCM通知正在Android上运行。在iOS上设置FCM时,还需要执行几个其他步骤。

  1. 配置APNs证书。 https://firebase.google.com/docs/cloud-messaging/ios/certs

  2. 上载您的APN。 https://firebase.google.com/docs/cloud-messaging/ios/client#upload_your_apns_certificate

  3. 您需要在Xcode的“签名和功能”下启用权利。Make sure the Backgroud fetch and Remote notification are checked

如果仍然出现错误,请确保在ios / Runner / GeneratedPluginRegistrant.m上具有以下内容

#import "GeneratedPluginRegistrant.h"

#if __has_include(<firebase_messaging/FLTFirebaseMessagingPlugin.h>)
#import <firebase_messaging/FLTFirebaseMessagingPlugin.h>
#else
@import firebase_messaging;
#endif

...

@implementation GeneratedPluginRegistrant

+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[FLTFirebaseMessagingPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTFirebaseMessagingPlugin"]];
...
}

@end