2016-05-05 14 views
0

私はAzure Mobile Appサービス内にプッシュ通知用に登録するモバイルアプリを持っています。 以前のバージョン(Azure Mobile Services)では、登録時にタグを追加できました。セキュリティ上の理由から、この可能性は現在のモバイルアプリサービスでは削除されました。 このフォーラムの別のスレッドでは、ターゲットとなる通知用のユーザーIDのようなタグを追加するカスタムAPIを作成する必要があることを読んでいます。 Azureのドキュメントには.NETだけしか記述されておらず、JavaScriptで行う必要があります。だから、私はこのAPIを書いた:iOSのAzure Mobile App通知ハブで目的のプッシュ通知に登録する方法

module.exports = { 
"put": function (req, res, next) { 

    var token = req.query.token; 
    token = token.replace('<',''); 
    token = token.replace('>',''); //Removing the token enclosures 
    token = token.replace(/\s+/g,''); //Removing the spaces in the token 
    req.azureMobile.push.apns.createNativeRegistration(token, req.azureMobile.user.id, function(error) { 
     if (error) { 
      console.log("Registration unsuccessful: ", error); 
      res.status(500).json({ error: error }); 
     } else { 
      var result = "Registration successful" 
      console.log(result); 
      res.status(201).json({result: result}); 
     } 
    }); 
} 
} 

私はこのスウィフトコードでのiOSからそれを呼び出しています:

self.client!.push?.registerDeviceToken(deviceToken, completion: {(error) in 
     var results = Dictionary<String, AnyObject>() 
     if error == nil { 
      let param = ["token":deviceToken] 
      AOAppDelegate.client!.invokeAPI("apnsRegistration", body: nil, HTTPMethod: "PUT", parameters: param, headers: nil, completion: {(objects, httpResponse, error) in 
       if error != nil { 
        print("Error registering for notifications: %@", error); 
       } 
      }) 
     } else { 
      print("Error registering for notifications: %@", error); 
     } 
    }) 

プロセスは私のiPhoneに完全に正常に動作しなく、私のiPadで、間違ったものはありません具体的にはこのiPadで、コードに何かがないと思うようになります。 Azure Portal内の通知ハブに行くと、うまく動作する登録済みのiPhone用に1つ以上のタグが登録されていると、0個のタグが登録されています。 テストプッシュ通知は、iPadのみではなく電話機に対しても通知を送信します。

提案がありますか?私のコードは意味がありますか?

ありがとう、

+0

テストプッシュがブロードキャストされているかどうかを確認します。はいの場合、それは登録の問題です。通知ハブの代わりにモバイルアプリAPIを使用しているようです。それも確認していただけますか?また、サービスバスエクスプローラを使用して登録とタグを確認する –

+0

返信Alexに感謝します。私はNotifications Hubを設定しましたが、Javascriptのハブを使ってタグを登録する方法に関するドキュメントは見つかりません。いくつかの情報をどこで見つけることができますか? azureのコード例は.NETのみに存在します。 –

答えて

3

コールは書き込みを見ません。

var promises = require('azure-mobile-apps/src/utilities/promises'); 

function createInstallation(context, installationId, pushChannel) { 
    var installation = { 
     installationId: installationId, 
     pushChannel: pushChannel, 
     platform: 'apns', 
     tags: [ 'some', 'list' ] 
    }; 

    return promises.wrap(context.push.createOrUpdateInstallation, context.push)(installation); 
} 

module.exports = { 
    post: function (req, res, next) { 
     var context = req.azureMobile, 
      installationId = req.get('X-ZUMO-INSTALLATION-ID'), 
      pushChannel: req.body.pushChannel; 

     createInstallation(context, installationId, pushChannel) 
     .then((result) => { 
      res.status(204).end(); 
     }); 
     .catch(next); 
    } 
} 

context.pushはNotification Hubs SDKをラップするだけで、そこから何かを使用できます。

+0

アドリアンに感謝します。 req.body.pushChannelは、リクエストの本文内でプッシュチャンネルを送信する必要があると想定していますか? –

+0

正しい - {"pushChannel": ""}のようなものを送ってください –

+0

私はAzureインストールIDとdeviceTokenだけを持っています。 pushChannelというプロパティや変数はありません。どこで入手できますか?あなたはデバイストークンを参照していますか? –

関連する問題