【问题标题】:Receiving fcm in iOS when app is foreground (flutter)当应用程序处于前台时(颤振)在 iOS 中接收 fcm
【发布时间】:2021-03-10 00:03:10
【问题描述】:

当应用打开时,我无法在 iOS 中显示消息。安卓运行良好。我正在接收消息,但格式类似于 = ['aps']['alert'],我可以以某种方式对其进行转换,以便能够使用本地通知包来显示它,就像我在 android 中显示的那样前景。

这就是我显示通知的方式(在 onMessage 中):

_notifications.showNotification(message['notification']['body']);

这是 fcm 的配置方式:

_fcm.requestNotificationPermissions(
    const IosNotificationSettings(sound: true, badge: true, alert: true));
_fcm.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
});
_fcm.getToken().then((value) {
});

当我从 firebase 控制台发送测试消息时出现问题。另外,如果我这样发送它们:

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

【问题讨论】:

    标签: ios firebase flutter firebase-cloud-messaging


    【解决方案1】:
    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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-19
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 1970-01-01
      • 2018-07-31
      相关资源
      最近更新 更多