2017-11-03 20 views
0

このコードはデバイスにテスト通知を受信しますが、エラーがない限りRegisterNativeAsyncへの呼び出しはありません。したがって、ハブはデバイスについてどのように知っていますか?SBNotificationHub.RegisterNativeAsync()は決して呼び出されないのに、デバイスは通知を受け取ることができますか?

[Register("AppDelegate")] 
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate 
    { 
     SBNotificationHub Hub { get; set; } 

     public const string ConnectionString = "Endpoint=xxx"; 

     public const string NotificationHubPath = "xxx"; 

     public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions) 
     { 
      var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, new NSSet()); 

      UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); 

      UIApplication.SharedApplication.RegisterForRemoteNotifications(); 

      global::Xamarin.Forms.Forms.Init(); 
      LoadApplication(new App()); 

      return base.FinishedLaunching(uiApplication, launchOptions); 
     } 

     public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) 
     { 
      // Create a new notification hub with the connection string and hub path 
      Hub = new SBNotificationHub(ConnectionString, NotificationHubPath); 



      // Unregister any previous instances using the device token 
      Hub.UnregisterAllAsync(deviceToken, (error) => 
      { 
       if (error != null) 
       { 
        // Error unregistering 
        return; 
       } 

       // Register this device with the notification hub 
       Hub.RegisterNativeAsync(deviceToken, null, (registerError) => 
       { 
        if (registerError != null) 
        { 
         // Error registering 
        } 
       }); 
      }); 
     } 
} 
+0

_ "エラーがない限り、' RegisterNativeAsync'は呼び出されません。 "私は 'UnregisterAllAsync'を呼び出す_no_エラーがあった場合、それとは逆のことをします。 –

+0

はい、あなたはポイントがあると思います。 –

+0

まだブレークポイントには達していませんが。 –

答えて

0
RegisteredForRemoteNotifications - Xamarinによると

この方法は、それ自体の登録とは何の関係もありません。 RegisteredForRemoteNotifications never triggered — Xamarin Forumsからわかるように、アプリケーションはそれをオーバーライドすることになっており、の後にと呼び出されたハンドラとして機能し、ユーザーがアプリケーションにプッシュ通知を受け取ることを許可します。

実際には、指定したコードはコードであり、ライブラリのものではありません。


そのようなものとしてXamarin.Azure.NotificationHubs.iOS.dll確認のILSpy逆コンパイルにUnregisterAllAsyncのソースコードを検査します。

関連する問題