简体   繁体   中英

Localized Notifications iOS 10 using FCM

We have a Django backend server using pyfcm to deliver Notifications throgh Firebase Cloud Messaging (FCM). I just updated to the today released Version 1.3.0. I want to send a notification using the loc-key and loc-args parameters so it can be displayed in the language the user is using on his phone. The notification reaches the device, it vibrates and makes the default sound for a new notification, but it will not displayed. It just happens nothing except for the sound and vibration.

This is the payload generated by the server which is sent to the fcm endpoint:

{  
   "notification": {  
      "loc-args": ["Demo (@demo)"],
      "loc-key": "notification-follow",
      "sound": "Default"
   },
   "priority": "high",
   "to": "..."
}

On the client side, this is what is received by the phone:

[  
   AnyHashable("gcm.message_id"):0:1496257581534217   %f910cc44f910cc44,
   AnyHashable("aps"):{  
      category = profile; 
    sound = Default;
   },
   AnyHashable("gcm.notification.alert"):{  
      "title-loc-key":" notification-follow",
      "title-loc-args":[  
         "Demo (@demo)"
      ]
   }
]

Is there anything I have to do before the message is displaying? Sending the message without the loc-key and loc-args but with message-body presents the notificaion on the device. Maybe the payload is wrong? How should it look like to do what I want? The key, notification-follow in this case, is listed and translated in the Localizable.strings files in any available language.

Ok, problem solved. It was pyFCM. I thought it would be an error with this library, so the developer pseudo-fixed it. But it worked properly, and now it doesn't work anymore. The trick is to give body_loc_args an array, otherwise it will give you an InvalidParameters error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM