0

私のフォームアプリケーションにプッシュ通知を統合しようとしました。 Azureメッセージングコンポーネントは、これを達成するために使用されます。 以下は私が使用しているコードです。私はRegisteredForRemoteNotificationsメソッドへのトリガーを取得しています。しかし、RegisterNativeAsyncメソッドは、仕事をしているようです。XamarinフォームでAzureプッシュ通知サービスを購読する

public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
{ 
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 
{ 
var push = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, 
new NSSet()); 
UIApplication.SharedApplication.RegisterUserNotificationSettings(push); 
UIApplication.SharedApplication.RegisterForRemoteNotifications(); 
} 
else 
{ 
const UIRemoteNotificationType not = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound; 
UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(not); 
} 
} 

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
{ 

     Hub = new SBNotificationHub(conStirng, NotifHubPath); 
     Hub.UnregisterAllAsync(deviceToken, (error) => 
     { 
      //Get device token 
      var id = deviceToken.ToString(); 
      var tag = "username"; 
      var tags = new List<string> { tag }; 
      Hub.RegisterNativeAsync(id, new NSSet(tags.ToArray()), (errorCallback) => 
      { 
       if (errorCallback != null) 
       { 
        //Log to output 
       } 
      }); 
     }); 
    } 

私はここで間違っていますか? Register機能が成功したか失敗したかを確認する方法はありますか?

答えて

0

登録メソッドの応答からのエラーがNULLかどうかを確認する必要があります。 nullの場合は成功したことを意味します。

var hub = new SBNotificationHub (cs, "your-hub-name"); 
    hub.RegisterNativeAsync (deviceToken, null, err => { 
     if (err != null) 
      Console.WriteLine("Error: " + err.Description); 
     else 
      Console.WriteLine("Success"); 
    }); 

Windowsユニバーサルアプリケーションの場合、レスポンスのregistrationIdプロパティを確認できます。

private async void InitNotificationsAsync() 
{ 
    var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync(); 

    var hub = new NotificationHub("<hub name>", "<connection string with listen access>"); 
    var result = await hub.RegisterNativeAsync(channel.Uri); 

    // Displays the registration ID so you know it was successful 
    if (result.RegistrationId != null) 
    { 
     var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); 
     dialog.Commands.Add(new UICommand("OK")); 
     await dialog.ShowAsync(); 
    } 

} 
+0

Nullは成功ですか? – TutuGeorge

+0

エラーがないことを意味します。従って成功。 – Aravind

関連する問題