Chakreshwar Sharma
Chakreshwar Sharma

Reputation: 2610

Receive push notification in IOS using gem fcm

I am using gem 'fcm' for sending push notifications. I am able to send the notifications on android but I am not receiving it in IOS. I am using the following code:

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)

I am able to receive the notification from Firebase console on my ios devise.

Upvotes: 2

Views: 1175

Answers (3)

Chakreshwar Sharma
Chakreshwar Sharma

Reputation: 2610

Finally, below works for me:

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)

Upvotes: 1

Raj
Raj

Reputation: 66

    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)

Upvotes: 0

buncis
buncis

Reputation: 2513

you forget to send the notification, you only send data

try to add notification: "your message" in your FCM class instatiation options

the whole options should be like this

options = {
data: {
    title: 'My title',
    message: 'My Message',
    event: 'message'

},
notification: {
    title: 'My title',
    message: 'My Message',
    event: 'message'

},
priority: 'high'
}

Upvotes: 1

Related Questions