我在使用Django + GCM向Android和iOS設備發送推送通知時遇到了一些問題。Python GCM使用Django向iOS和Android主題發送推送通知
問題1:機器人在背景當接收推送但該方法onMessageReceived
不被調用。所以我無法處理收到的數據。如果應用程序已打開或最小化,iOS應用程序關閉時纔會收到推送,但未收到推送。
@Override
public void onMessageReceived(String from, Bundle data) {
....
}
Django的代碼:
@receiver(post_save, sender=Notification)
def send_push(sender,**kwargs):
n = kwargs.get('instance')
gcm = GCM("API_KEY")
data = {'messageContent': n.message, 'content_available':'true'}
notification = {'body': n.message, 'title': n.title,'sound':''}
topic = n.topic
gcm.send_topic_message(topic=topic, data=data,notification=notification)
問題2:Android的接收推手在背景和方法onMessageReceived
被調用(Android的行)。但iOS應用程序沒有收到任何通知,已打開,關閉,最小化。只是不會工作。
的Django代碼:
@receiver(post_save, sender=Notification)
def send_push(sender,**kwargs):
n = kwargs.get('instance')
gcm = GCM("API_KEY")
data = {'messageContent': n.message, 'content_available':'true',
'title': n.title, 'sound':'' }
topic = n.topic
gcm.send_topic_message(topic=topic, data=data)