2016-02-19 73 views
0

我在使用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) 

回答

0

可能不是你所期待的,但使用像Django的pushnotifications與我github.com工作以及提供在Android GCM實例庫。

0

我已經使用過的#1解決方案/方法。

from gcm import * 

gcm = GCM("MY_GCM_KEY") 
data = {'the_message': 'You have x new friends', 'param2': 'value2'} 

reg_id = 'REG IDS' 

gcm.plaintext_request(registration_id=reg_id, data=data)