简体   繁体   English

当应用程序处于前台时(颤动)在 iOS 中接收 fcm

[英]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.

相关问题 当应用程序在 iOS 前台时如何处理 Flutter FCM 推送通知? - How to handle Flutter FCM push notification when app in foreground for iOS? Flutter iOS 应用程序在前台时的 FCM 推送通知 - Flutter FCM push notification for iOS when app is in foreground 当应用程序在后台并在前台接收时,为什么在 IOS 上收不到 FCM 通知? Flutter - Why does not receive FCM notifications on IOS when the app is in background and receive in foreground? Flutter iOS-在前台接收FCM推送消息 - iOS - Receiving FCM push messages in foreground Fcm:当应用程序在后台和前台时向 Android 和 IOS 发送 DataMessage - Fcm: Send DataMessage to Android and IOS when app is in background and in foreground 当应用程序在前台时,IOS Play Sound接收推送通知 - IOS Play Sound on receiving push notification when app in foreground iOS应用程序未通过FCM控制台接收消息 - Ios App not receiving message through FCM console FCM未在iPhone 8前台模式下接收 - FCM is not receiving in iphone 8 foreground mode 应用程序处于前台时未收到推送通知 ios flutter - Push Notification not received when app is in foreground ios flutter Flutter FCM 推送通知未在 IOS 上接收到 firebase_messaging:^9.1.3 - Flutter FCM push notification not receiving on IOS with firebase_messaging: ^9.1.3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM