【问题标题】:IONIC 3: Unable to receive push notification on foreground in IOSIONIC 3:无法在 IOS 前台接收推送通知
【发布时间】:2019-05-15 17:52:09
【问题描述】:

我正在开发与购物相关的移动应用程序,并使用 firebase FCM 在其中实现推送通知。在 android 上一切正常,我通过代码很好地收到了通知:

app.component.ts

platform.ready().then(() => {
   this.fcm.onNotification().subscribe(data => {
      console.log(data);
   });
});

它在 android 中成功显示通知数据,但在 IOS 中,当我点击我的 php 代码进行通知时,它在我的应用程序关闭时显示通知,但当我已经打开应用程序时它没有执行this.fcm.onNotification()函数。我只是调试了这个问题并注意到了这一点,在我的 xcode 控制台中显示:

2018-12-14 18:08:34.299048+0530 BeMeals[1351:322531] 
Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: 
but the completion handler was never called.

php 文件

$url = 'https://fcm.googleapis.com/fcm/send';
    $msg = array
    (
     'title'  => 'This is title', // type of notification
     'tickerText' => 'This is message', // message
     'tab' => 'This is tab', // screen to open based on subtitle
     'screen' => "request_list",
     'message'  => 'hey',
     'body' => 'test',
     'vibrate' => 1,
     'sound'  => 1,
     'click_action'=>'FCM_PLUGIN_ACTIVITY'
    );

    $fields = array
    (
     'registration_ids'  => ['my device token'],
     'notification'   => $msg,
     'data' => [
        'test'=>123
     ],
     'priority' => 'high',
     'content_available' => true
    );

    $headers = array
    (
     'Authorization: key=' . self::$API_ACCESS_KEY,
     'Content-Type: application/json'
    );

    $result = self::useCurl($url, $headers, $fields);

谁能告诉我为什么会这样?出了什么问题?

【问题讨论】:

    标签: ios firebase cordova ionic3 cordova-plugin-fcm


    【解决方案1】:

    在google上的一些RND为自己找到解决方案后,您需要将FCM Plugin版本降级为1.1.5

    cordova-plugin-fcm: "^1.1.5"
    

    将此添加到您的package.json 文件中。 希望这对你也有用。

    【讨论】: