前提・実現したいこと
MonacaとNCMBを用いてプッシュ通知のグルーピング配信を実現したいのですが、
その際にアプリからNCMBのinstallationsクラスのchennelsの更新をしたいです。
デバイストークンの登録まではできますが、channelsの更新ができません
以下コードです。
原因や実現方法などご教示お願い致します。
※初投稿となっております。何か不足している情報などあればご指摘いただけると幸いです。
該当のソースコード
// [NCMB] API Key var applicationKey = "アプリケーションキー"; var clientKey = "クライアントキー"; var strObjID = localStorage.getItem('objID'); // SDKの初期化 var ncmb = new NCMB(applicationKey, clientKey); var id =""; // installationのすべてのkey var keys = new Object(); // installationのobjectId //var installation_objectId = ""; // installationのすべてのkey var keys = new Object(); function loginID() { var userID = document.getElementById("userID").value; var orgID = document.getElementById("orgID").value; alert("uid:"+userID + "/oID:" + orgID+"でログインします"); /*サーバーへ接続して戻り値がtrueならログイン成功*/ var srvRtn =isLogin(userID,orgID); if(srvRtn){ alert("ログイン成功"); /*ホーム画面へ*/ localStorage.setItem('userID', userID); localStorage.setItem('orgID', orgID); alert("入力済ID登録完了"); window.NCMB.monaca.setDeviceToken(applicationKey,clientKey); alert("デバイストークン登録完了"); getInstallationId(); alert("installation情報取得完了"); alert("test"); var strUID = localStorage.getItem('userID'); alert("ストレージに登録したUID:"+strUID); var strOID = localStorage.getItem('orgID'); alert("ストレージに登録したOID:"+strOID); window.location.href = 'home.html'; } else{ alert("ログイン失敗"); /*ホーム画面へ*/ } //ここから下の処理に行かない } function isLogin(uid,oid) { alert(uid +"/"+oid+"をサーバーへ渡します(戻り値:True)"); return true; } function getInstallationId() { window.NCMB.monaca.getInstallationId(function(id) { // ここに処理を記述 alert("objID:" + id); localStorage.setItem('objID',id); }); } function changeChOff() { alert("objId:"+strObjID+"を配信対象外にします。"); window.NCMB.monaca.getInstallationId(function(id) { ncmb.Installation.fetchById(id) .then(function(installation){ installation.set("channels", "off"); return installation.update(); }) .catch(function(err) { // エラー処理 }) }); } function changeChOn() { alert("objId:"+strObjID+"を配信対象にします。"); window.NCMB.monaca.getInstallationId(function(id) { ncmb.Installation.fetchById(id) .then(function(installation){ installation.set("channels", "on"); return installation.update(); }) .catch(function(err) { // エラー処理 }) }); }
あなたの回答
tips
プレビュー