簡體   English   中英

向知道電話號碼的特定設備發送推送通知,parse.com

[英]Sending push notification to specific device knowing phone number, parse.com

我只是想在這里澄清一下,如果可能的話,如果可能更好的話,我會提出其他建議。

這是我的應用程序現在的工作方式:

1)如果匿名用戶是第一次打開應用程序,則將創建該用戶

2)需要進行電話驗證。 如果通過驗證,我會將電話號碼保存在用戶對象的自定義字段中(在此之后我是否需要將該用戶設置為真實用戶,還是可以和匿名用戶一起使用?)(驗證當然僅一次)

3)用戶將能夠從他的聯系人列表(ABPeoplePicker)中選擇一個朋友,然后將推送通知發送到該朋友的設備。

現在,我使用以下代碼與用戶和安裝對象建立了關系:

PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];

這創建了一個指向用戶ObjectId的指針

所以我的問題是我將如何創建查詢並將推式通知發送到從該用戶朋友列表中檢索到的號碼? 我很難將如何從電話號碼連接到需要將通知發送到的安裝設備。 如果您可以提供JavaScript方面的幫助,因為我閱讀過,通過雲代碼發送它會更安全!

如果我需要使匿名用戶成為真實用戶,也可以提到上述子問題。

非常感謝!!

我建議為每個用戶訂閱他們自己的頻道,頻道名稱等於他們的電話號碼(無法使用Javascript進行訂閱):

NSString *userPhoneNumber = ... 

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
// "x" added to the beginning of the userPhoneNumber since
// Parse doesn't allow channels to begin with a number
[currentInstallation addUniqueObject:[NSString stringWithFormat:@"x%@", userPhoneNumber] forKey:@"channels"];
[currentInstallation saveInBackground];

這樣,在推送通知之前無需查詢:

var friendPhoneNumber = ...
var friendChannel = "x" + friendPhoneNumber;
Parse.Push.send({
  channels: [ friendChannel ],
  data: {
    alert: message
  }
}, {
  success: function() {
    // Push was successful
  },
  error: function(error) {
    // Handle error
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM