2016-05-25 11 views
0

Parseで特定のユーザーに通知を送信しようとしています。私は主題についていくつかの質問を読んだが、それについて私の頭をはっきりと見ることはできない。私は、クラウドコード(ジャバスクリプト)でこの機能を持っている:Swift:通知を送信するユーザーインストールIDを取得する

Parse.Cloud.define("sendPushToUser", function(request, response) { 

    var senderUser = request.user; 
    var recipientUserId = request.params.recipientId; 
    var message = request.params.message; 

    // Validate that the sender is allowed to send to the recipient. 
    // For example each user has an array of objectIds of friends 
    //if (senderUser.get("friendIds").indexOf(recipientUserId) === -1) { 
    //response.error("The recipient is not the sender's friend, cannot send push."); 
    //} 

    // Validate the message text. 
    // For example make sure it is under 140 characters 
    //if (message.length > 140) { 
    // Truncate and add a ... 
    //message = message.substring(0, 137) + "..."; 
    //} 
    // Send the push. 
    // Find devices associated with the recipient user 
    var recipientUser = new Parse.User(); 
recipientUser.id = recipientUserId; 
    var pushQuery = new Parse.Query(Parse.Installation); 
    pushQuery.equalTo("user", recipientUser); 
    // Send the push notification to results of the query 
    Parse.Push.send({ 
    where: pushQuery, 
    data: { 
     alert: message 
    } 
    }).then(function() { 
     response.success("Push was sent successfully."); 
    }, function(error) { 
     response.error("Push failed to send with error: " + error.message); 
    }); 
}); 

だから私は私のXcodeプロジェクト内の関数を呼び出す前に、受信者のユーザーIDでインストールを渡ししようとしています。最初は、_User.objectIdを使用するはずだと思っていましたが、インストール先を指定する必要があるようです。だから、私は_Installationクラスから特定のユーザーのインストールを取得しようとしましたが、「クライアントがインストール・コレクションで検索機能を実行できません」というエラーが表示されます。

どのようにすればいいと思いますか?私は代わりに機能のインストールを取得しようとする必要がありますか?

EDIT:「コンソールログは、「インストールのSEND」

var sendeeInstallation = PFInstallation.query() 
        var sendeeId = PFUser.currentUser()?.objectId 
        sendeeInstallation!.whereKey("User", equalTo: "sendeeId") 
        println("SEND INSTALLATION") 
        sendeeInstallation!.findObjectsInBackgroundWithBlock({ (results:[AnyObject]?, error:NSError?) -> Void in 
         println("FIND DONE \(results![0].objectId)") 

が、「DONE FIND」ではないので、それは私ができるようだ:チェックした後、問題はここでは特に、私のスウィフトコードであると思われます_Installationクラスのfind関数を使用します。どのように私はこれを回避することができます任意のアイデア? _Userクラスに_Installationにリンクするポインタを使用することを考えていますが、あまりにもエレガントではありません。クラウドコードを介してユーザーに通知するのではなく、インストールに通知を送信する必要があると想定するのは正しいですか?

答えて

0

クライアントはインストールコレクションで検索機能を実行できません。真のPush.send上:

許可は十分ではない、あなたがuseMasterKey使用することができますMASTERKEY

を使用するようにしてください。使用方法は次のとおりです

Parse.Push.send({ 
    where: pushQuery, 
    data: { 
     alert: message 
    }, useMasterKey:true 
    }) 
+0

私の質問は、Swiftコードとjavascriptサーバーコードではないので、私の質問を編集しました。 –

関連する問題