使用 gem fcm 在 IOS 中接收推送通知



我正在使用gem 'fcm'发送推送通知。我可以在安卓上发送通知,但我在 IOS 中没有收到通知。我正在使用以下代码:

fcm = FCM.new('my key', timeout: TIMEOUT)
options = {
    data: {
        title: 'My title',
        message: 'My Message',
        event: 'message'
    },
    priority: 'high'
}

response = fcm.send(['fcm registered device id of ios'], options)

我能够在我的 ios 设备上从 Firebase 控制台接收通知。

您忘记发送通知,则只发送数据

尝试在 FCM 类设置选项中添加notification: "your message"

整个选项应该是这样的

options = {
data: {
    title: 'My title',
    message: 'My Message',
    event: 'message'
},
notification: {
    title: 'My title',
    message: 'My Message',
    event: 'message'
},
priority: 'high'
}

最后,下面对我有用:

fcm = FCM.new(Rails.application.secrets.fcm_api_key, timeout: Settings.timeout)
options = {
  data: {
    title: "title",
      message: "message",
      event: ':message',
      notification_type: "Notification.notification_types[notification_type]",
      unread_count: "receiver.unread_notification_count",
      notification_id: "id",
      resource_type: "resource_type",
      resource_id: "resource_id",
      unread: "unread",
      has_action_performed: "has_action_performed"
    },
     notification: {
       body: "helldddo!",
       title: "Shivadm",
       sound: "default",
       click_action: "FCM_PLUGIN_ACTIVITY",
       badge: 3
     },
     priority: 'high',
   }
  response = fcm.send([fcm_id]], options)
    fcm_client = FCM.new(your_firebase_key)
    registration_ids= [user_device_token]
    options = {
        priority: 'high',
        data: {
            message: message,
            event: 'event'
        },
        notification: {
            body: message,
            event: 'event',
            sound: 'default'
        }
    }
    fcm_client.send(registration_ids, options)

相关内容

  • 没有找到相关文章

最新更新