2014-10-07 135 views
1

我正在編寫Android應用程序關於共享不同的內容。現在我開發了社交網絡,當一個用戶添加新朋友時,發送用戶添加的Parse Push通知。發送解析推送通知與特定用戶

我使用Parse SDK,現在我不知道該怎麼做。

我試試這個:

ParseInstallation installation = ParseInstallation.getCurrentInstallation(); 
installation.put("userId",id); 
try { 
    installation.save(); 

此創建安裝類解析數據的用戶ID列。 (我看到解析數據和用戶id列是從用戶的正確ID)

接下來我做的:

//Create our Installation query 
    ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery(); 
    pushQuery.whereEqualTo("userId",ParseUser.getCurrentUser().getObjectId()); 

    // Send push notification to query 
    ParsePush push = new ParsePush(); 
    push.setQuery(pushQuery); // Set our Installation query 
    push.setMessage("Willie Hayes injured by own pop fly."); 
    push.sendInBackground(); 

我創建了比較用戶id柱上進行(包含來自用戶的是添加你的用戶id查詢)與當前的ParseUser,但推送不發送,沒有人收到。

請幫幫我。

謝謝。

回答

1

我所做的是將設備註冊到與用戶對應的頻道。在Swift中,我是這樣做的,但在Android中它會非常相似。這意味着用戶「userId」將訂閱頻道「user_userId」。

let currentInstallation = PFInstallation.currentInstallation() 
currentInstallation.channels = ["user_" + PFUser.currentUser().objectId] 
currentInstallation.saveInBackground() 

然後當你想發送推送,發送到頻道「user_userId」。