Flutter ios 设备不会触发来自 FCM 的消息通知。发送设备在实现 APNs 时失败



在我的fcm云功能中,向其他玩家发送通知,当我添加apns层时,它无法发送。当apns层被删除时,通知会出现在android上,但对于iOS,通知会在前端接收,但无法触发onMessage功能来显示警报对话框。

var payload = {
data: {
click_action: "FLUTTER_NOTIFICATION_CLICK",
notificationType: "friendsRequest",
fromUsername: fromUsername,
fromProfilePic: fromProfilePic,
fromColorIndex: fromColorIndex,
type: type
},
};

该有效载荷返回服务器响应"0";崩溃";

要为iOS启用通知,您需要首先为iOS设置FCM:正如您所说,您已经生成了APN。确认一下你有没有把apn和firebase项目联系起来。之后,在Xcode中打开您的项目ios模块,并在AppDelegate 中进行以下更改

if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? 
UNUserNotificationCenterDelegate
}

在颤振侧进行更改(我在启动屏幕中使用此代码(:

初始化

FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();

initState((中的代码

var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher'); //replace with your app icon file
var initializationSettingsIOS = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
FirebaseNotifications().setUpFirebase(_firebaseMessaging);
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
showNotification(
message['notification']['title'], message['notification']['body']);
print("onMessage: $message");
},
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
},
);

通知方式:

void showNotification(String title, String body) async {
await _demoNotification(title, body);
}
Future<void> _demoNotification(String title, String body) async {
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'channel_ID', 'channel name', 'channel description',
importance: Importance.Max,
playSound: true,
sound: 'sound',
showProgress: true,
icon: 'notification_icon',
color: AppTheme.secondaryaccent,
priority: Priority.High,
ticker: 'test ticker');
var iOSChannelSpecifics = IOSNotificationDetails();
var platformChannelSpecifics = NotificationDetails(
androidPlatformChannelSpecifics, iOSChannelSpecifics);
await flutterLocalNotificationsPlugin
.show(0, title, body, platformChannelSpecifics, payload: 'test');
}

相关内容

  • 没有找到相关文章

最新更新