2016-01-24 94 views
0

我試圖推送通知發送給單個用戶,我跟着指示找到無法推送通知發送到與解析單個用戶 - 斯威夫特

這裏是我的代碼:

let message = "Alert !!" 
    let id = "QlhXkNWET6" 

    let data = [ "title": "Some Title", 
     "alert": message] 

    let userQuery: PFQuery = PFUser.query()! 
    userQuery.whereKey("objectId", equalTo: id) 
    let query: PFQuery = PFInstallation.query()! 
    query.whereKey("currentuser", matchesQuery: userQuery) 

    let push: PFPush = PFPush() 
    push.setQuery(query) 
    push.setData(data) 
    push.sendPushInBackgroundWithBlock { (success:Bool, error:NSError?) -> Void in 
     if success{ 
      print("success") 
     } 
     else{ 
      print(error) 
     } 
    } 

我調試了這段代碼,我能夠達到「成功」的聲明。

但是在解析網站,我得到以下錯誤:

PUSH ID 
JXJmO93vau 

TARGETING 
currentUser advanced operator ($inQuery {"className"=>"_User", "where"=>{"objectId"=>"QlhXkNWET6"}}) 
SENDING TIME 
January 23rd, 2016 at 8:14 PM 

EXPIRATION 
None 

FULL TARGET 
{ 
    "currentUser": { 
    "$inQuery": { 
     "className": "_User", 
     "where": { 
     "objectId": "QlhXkNWET6" 
     } 
    } 
    } 
} 

FULL DATA 
{ 
    "alert": "Alert !!", 
    "title": "Some Title" 
} 

ERROR: 
error 102: bad type for $inQuery parse.com/api/collections/collection.go:393 
inQueryVisitor.runChildQuery parse.com/api/collections/collection.go:367 
inQueryVisitor.Visit <autogenerated>:171 (*inQueryVisitor).Visit  
parse.com/api/types/query/visitor.go:27 Visit 
parse.com/api/collections/collection.go:407 (*Collection).resolveInQueries 
parse.com/api/collections/collection.go:554 (*Collection).PrepareQuery 
parse.com/api/collections/installation_collection.go:740 
(*InstallationCollection).Iterate parse.com/push/expansion/expansion_job.go:360 
(*Job).iterateOverDevices parse.com/push/expansion/expansion_job.go:296 
(*Job).perform parse.com/push/expansion/expansion_job.go:184 (*Job).Perform 
parse.com/resque/service.go:420 (*Service).perform parse.com/resque/service.go:144 
(*Service).Work.func1 /usr/local/go/src/runtime/asm_amd64.s:1722 goexit 

任何幫助將不勝感激!

回答

0

我能夠通過在PFInstallation中創建一個「currentuser」列並首先向其註冊當前用戶來解決此問題。我放棄了使用「ObjectId」的想法,因爲使用電子郵件更有意義。

這是在用戶第一次註冊時完成的。

let pushQuery = PFInstallation.query() 
    pushQuery!.whereKey("user", equalTo: "[email protected]") 

    // Send push notification to query 
    let push = PFPush() 
    push.setQuery(pushQuery) // Set our Installation query 
    push.setMessage("New Message In coming") 
    push.sendPushInBackground() 

let currentInstallation = PFInstallation.currentInstallation() 
currentInstallation.addUniqueObject("currentuser", forKey: "channels") 
currentInstallation["currentuser"] = self.emailTF.text! // adding this user email 
currentInstallation.saveInBackground() 

現在這個網友認爲,註冊完成後,你可以通過執行以下操作,添加以下內容到一個按鈕或其他任何地方發送推送通知給該用戶