在IOS模拟器中运行我的应用程序时,出现此错误:有人知道原因吗?
顺便说一句,它适用于Android。
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();
}
答案 0 :(得分:0)
我假设FCM通知正在Android上运行。在iOS上设置FCM时,还需要执行几个其他步骤。
配置APNs证书。 https://firebase.google.com/docs/cloud-messaging/ios/certs
上载您的APN。 https://firebase.google.com/docs/cloud-messaging/ios/client#upload_your_apns_certificate
如果仍然出现错误,请确保在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