2017-11-03 6 views
0

Dieser Code führt dazu, dass das Gerät eine Testbenachrichtigung erhält. Es wird jedoch kein Anruf an RegisterNativeAsync gesendet, es sei denn, es liegt ein Fehler vor. Wie weiß also der Hub über das Gerät?Wie kann das Gerät Benachrichtigungen empfangen, obwohl SBNotificationHub.RegisterNativeAsync() nie aufgerufen wird?

[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

_ "aber es gibt keinen Aufruf an' RegisterNativeAsync', außer es liegt ein Fehler vor. "_ - wirklich? Ich sehe genau das Gegenteil, es heißt, wenn _no_ error "UnregisterAllAsync" aufrufen würde. –

+0

Ja, ich denke, Sie können einen Punkt haben. –

+0

Obwohl noch keinen Breakpoint getroffen. –

Antwort

0

Nach RegisteredForRemoteNotifications - Xamarin, diese Methode hat nichts mit dem zu tun, selbst Registrierung. Soweit ich kann von RegisteredForRemoteNotifications never triggered — Xamarin Forums sagen, Anwendungen sollen es außer Kraft setzen, und es dient als ein Handler, der aufgerufen wird nach der Benutzer ermöglicht der Anwendung Push-Benachrichtigungen erhalten.

Tatsächlich ist der Code, den Sie angegeben haben, Ihr Code, nicht Bibliotheks.


und bestätigt in ILSpy Dekompilierung Xamarin.Azure.NotificationHubs.iOS.dll den Quellcode UnregisterAllAsync Prüfung als solche.

Verwandte Themen