2017-10-20 39 views
0

誰でもAzure通知ハブを手伝って、デバイスインストールフォームC#コードの設定方法を教えてください。私はインストールオブジェクトに問題があります。ハブクライアントインスタンスのCreateOrUpdateInstallationメソッドにパラメータとして渡すように設定する方法。それは私には分かりません。Azure通知ハブのインストールC#

私は地元の魅力のようなデバイス登録で動作する紺碧のハブを持っていますが、紺碧にアップロードされていません。今私はアイテレーションを試してみたい。

のthnx

は更新:4日後、私は自分自身に通知を送信することができないことを、考え出しました。 Azureは、あなたがあなたの電話に通知を送信していることを何とか知っています。それが私の歓迎メッセージが私の電話に届かなかった理由です。

更新:同じエンドポイントの呼び出しはiOSのそれではない作品から来た場合、今、私は郵便配達で、このエンドポイントを打ったとき、それが動作

[HttpGet] 
[Route("api/push/test-installation")] 
public async Task<IActionResult> NotificationInstalationTest() 
{ 
string connectionString = "{{my connection string}}"; 
string hubName = "{{my hub name}}"; 
string token = "{{tokne}}"; 

NotificationHubClient hubClient = NotificationHubClient.CreateClientFromConnectionString(connectionString, hubName); 

string notificationText = $"Test message for Azure delivery for Atila at: {DateTime.Now.ToShortTimeString()}"; 

var alert = new JObject 
(
     new JProperty("aps", new JObject(new JProperty("alert", notificationText))), 
     new JProperty("inAppMessage", notificationText) 
).ToString(Newtonsoft.Json.Formatting.None); 

IList<string> tags = new List<string>(); 
tags.Add("email"); 

IDictionary<string, string> pushVariables = new Dictionary<string, string>(); 
pushVariables.Add("email", "[email protected]"); 

Installation installation = new Installation(); 
installation.InstallationId = Guid.NewGuid().ToString(); 
installation.Platform = NotificationPlatform.Apns; 
installation.PushChannel = token; 
installation.Tags = tags; 
installation.PushVariables = pushVariables; 

await hubClient.CreateOrUpdateInstallationAsync(installation); 
NotificationOutcome result = await hubClient.SendAppleNativeNotificationAsync(alert); 

return Ok("Success"); 
} 

:これは私が私のバックエンドのコードデバイスをインストールする方法今です!ハブのクライアント・インスタンスのCreateOrUpdateInstallationメソッドにパラメータとして渡すためにそれを設定する方法

のthnx

答えて

0

。それは私には分かりません。

私の理解に基づいて、インストールモデルを使用してバックエンドから通知ハブを登録しています。あなたのWebAPIのプロジェクトの場合は、次のように作成/インストールを更新するためのあなたの方法と仮定すると:あなたのモバイルクライアントのために

InstallationController.cs

//PUT api/installation 
public async Task<HttpResponseMessage> Put(DeviceInstallation deviceUpdate) 
{ 
    Installation installation = new Installation(); 
    installation.InstallationId = deviceUpdate.InstallationId; 
    //TODO: 
    await hub.CreateOrUpdateInstallationAsync(installation); 
    return Request.CreateResponse(HttpStatusCode.OK); 
} 

を、次の方法を参照してください可能性:

private async Task<HttpStatusCode> CreateOrUpdateInstallationAsync(DeviceInstallation deviceInstallation) 
{ 
    using (var httpClient = new HttpClient()) 
    { 
     //TODO: set your authorization header 
     //httpClient.DefaultRequestHeaders.Authorization 

     var putUri =$"{your-backend-endpoint}/api/installation"; 
     string json = JsonConvert.SerializeObject(deviceInstallation); 
     var response = await httpClient.PutAsync(putUri, new StringContent(json, Encoding.UTF8, "application/json")); 
     return response.StatusCode; 
    } 
} 

また、詳細についてはを参照してください。 10およびhereを使用して、インストールモデルを使用してバックエンドを構築する登録モデルでバックエンドを構築します。

+0

thnxです。はい、私はAzureにアップロードするとき、登録が機能しないので、それは単純にメッセージを配信しないので、私はバックエンド経由でデバイスをインストールしようとしています。私が郵便配達員とコントローラを叩いたときにのみ、デバイスのインストールはAzureで動作します。何か案が? – Wasyster

+0

IOSからエンドポイントを呼び出す際に例外がありますか?この問題のトラブルシューティングについては、[ここ](https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-fixer)に従ってください。 –

+0

例外はありません。それが問題です。それはブラックボックスのようなもので、デバイスから電話が来たときにプッシュされない理由はわかりません。 – Wasyster

関連する問題