簡體   English   中英

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

[英]Receive push notification in IOS using gem fcm

我正在使用gem 'fcm'發送推送通知。 我可以在Android上發送通知,但我沒有在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_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)

最后,下面對我有用:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM