2016-01-24 56 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() 

现在这个网友认为,注册完成后,你可以通过执行以下操作,添加以下内容到一个按钮或其他任何地方发送推送通知给该用户