Chitrank-Dixit / django-fcm

Django FCM provides firebase cloud messaging to android or ios support for django apps
https://django-fcm.readthedocs.io/en/latest/
MIT License
54 stars 28 forks source link

iOS payload problem #33

Open mirzadelic opened 7 years ago

mirzadelic commented 7 years ago

Does anyone have problem with iOS devices that they can't receive message from django-fcm? Android receives it, and when test from firebase console ios device receive message, just when using with django-fcm i can't get it work?

danielchristopher1 commented 7 years ago

+1

nwvaras commented 7 years ago

+1 Any news on this?

claudiocleberson commented 7 years ago

Guys, If anyone has that problem, try to fix that by putting a 'notification" payload as the example below .

That works for me when the iOS is in background. I think that is missing in the docs. The iOS only will get background push, if 'content_available': True, and content inside the 'notification' payload is set.

devices.send_message({'message': request.data['body'], 'title': title, 'type': 'chat', 'fromjid':request.data['fromjid']}, notification={ 'content_available': True, 'body': request.data['body'], 'title': title}, priority="high"), status = status.HTTP_200_OK)

cheers,

hungnv132 commented 7 years ago

Thanks so much @claudiocleberson. It worked.

joshisumit commented 7 years ago

@hungnv132 @claudiocleberson,

I am trying the same for IOS, but it is not working for me. Below is my code:

user_phone = Device.objects.get(name='user1')

res = user_phone.send_message( { 'message':notification_message, 'type':'optyLost', 'notification':{ 'content_available':True, 'priority':'high', 'body':notification_message, 'category':'notification_category' } })

It is not sending notification to IOS device. Please help.

hungnv132 commented 7 years ago

@joshisumit I think you pass wrong parameters to the method send_message. Here is my way:

class UserDevice(AbstractDevice): def send_notification(self, message, title='Thông báo', sound='default', options): data = { 'title': title, 'message': message, 'type': 'chat' } notification = { 'title': title, 'body': message, 'sound': sound, 'content_available': True } return self.send_message(data=data, notification=notification, priority="high", options)

joshisumit commented 7 years ago

Thank you so much @hungnv132 It worked for me.