【问题标题】:Receive push notification in IOS using gem fcm使用 gem fcm 在 IOS 中接收推送通知
【发布时间】:2017-11-16 07:38:48
【问题描述】:

我正在使用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 控制台的通知。

【问题讨论】:

    标签: android ios ruby-on-rails firebase firebase-cloud-messaging


    【解决方案1】:

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

    尝试在您的 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'
    }
    

    【讨论】:

      【解决方案2】:
          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)
      

      【讨论】:

        【解决方案3】:

        最后,以下对我有用:

        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)
        

        【讨论】:

          猜你喜欢
          • 2018-04-22
          • 2017-06-13
          • 1970-01-01
          • 2021-02-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多