[英]Receiving fcm in iOS when app is foreground (flutter)
I'm not able to show message in iOS when app is open.当应用程序打开时,我无法在 iOS 中显示消息。 Android working fine.
Android 工作正常。 I am receiving message but is in a form something like = ['aps']['alert'], can I somehow convert it so I would be able to use local notification package to show it, like I am showing in android back and foreground.
我正在接收消息,但格式类似于 = ['aps']['alert'],我可以以某种方式对其进行转换,以便能够使用本地通知 package 来显示它,就像我在 android 中显示的那样前景。
This is how I'm showing the notification (in onMessage):这就是我显示通知的方式(在 onMessage 中):
_notifications.showNotification(message['notification']['body']); _notifications.showNotification(message['notification']['body']);
This is how fcm is configured:这是 fcm 的配置方式:
_fcm.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
_fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
});
_fcm.getToken().then((value) {
});
Problem occurs when I'm sending test messages from firebase console.当我从 firebase 控制台发送测试消息时出现问题。 Also if I send them like this:
另外,如果我这样发送它们:
public static function sendNotificationToRegisteredUsers($message){
$msg = array
(
'body' => $message,
'title' => 'Test',
'vibrate' => 1,
'sound' => 1,
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);*/
);
$fields = array
(
'to' => '/topics/TestTopic',
'notification' => $msg,
'priority' => 'high',
'android' => [
//'collapseKey' => 'daily_event',
'priority' => 'high',
/*'notification' => [
'sound' => 'default'
]*/
],
'apns' => [
'headers' => [
'apns-priority' => '10'
],
'payload' => [
'aps' => [
'alert' => [
'title' => 'Test',
'body' => $message,
],
'badge' => 42,
],
],
]
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
}```
Thank you
Add the following lines to the didFinishLaunchingWithOptions method in the AppDelegate.m/AppDelegate.swift file of your iOS project
Objective-C:
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
Swift:
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.