django-fcm icon indicating copy to clipboard operation
django-fcm copied to clipboard

iOS payload problem

Open mirzadelic opened this issue 8 years ago • 7 comments

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?

mirzadelic avatar Dec 25 '16 17:12 mirzadelic

+1

danielchristopher1 avatar Feb 05 '17 19:02 danielchristopher1

+1 Any news on this?

nwvaras avatar Jul 30 '17 08:07 nwvaras

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,

claudiocleberson avatar Aug 09 '17 17:08 claudiocleberson

Thanks so much @claudiocleberson. It worked.

hungnv132 avatar Sep 21 '17 10:09 hungnv132

@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.

joshisumit avatar Sep 26 '17 13:09 joshisumit

@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)

hungnv132 avatar Sep 27 '17 03:09 hungnv132

Thank you so much @hungnv132 It worked for me.

joshisumit avatar Sep 27 '17 09:09 joshisumit