2017-10-12 8 views
0

Ich verwende Xam.Plugins.Notifier-Paket, um lokale Benachrichtigung in Xamarin.Forms-Projekt zu implementieren.Xam.Plugins.Notifier funktioniert nicht auf IOS 11

Hier ist der Code, den ich im PCL-Projekt geschrieben habe. CrossLocalNotifications.Current.Show ("Titel", "Beschreibung");

Es funktioniert gut auf Android, aber es funktioniert nicht auf IOS. Ich bin mir nicht sicher, ob es auf niedrigeren IOS SDK funktioniert. Auf jeden Fall ist es nicht auf IOS arbeiten 11.

Hier ist der Code, den ich in AppDelegate.cs hinzugefügt

  if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) 
      { 
       // Ask the user for permission to get notifications on iOS 10.0+ 
       UNUserNotificationCenter.Current.RequestAuthorization(
        UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, 
        (approved, error) => { }); 
      } 
      else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) 
      { 
       // Ask the user for permission to get notifications on iOS 8.0+ 
       var settings = UIUserNotificationSettings.GetSettingsForTypes(
        UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, 
        new NSSet()); 

       UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); 
      } 

Kann jemand mir helfen, es zu beheben? Ich möchte dieses Paket auf IOS arbeiten lassen.

Danke.

Antwort

0

Welches Szenario funktioniert nicht? Aktiv oder im Hintergrund?

Wenn es nicht funktioniert, wenn es aktiv ist, können Sie die Delegierten (Subklassen UNUserNotificationCenterDelegate)

Ändern Sie den Code wie unten Griff vergessen:

if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0)) 
{ 
    // Ask the user for permission to get notifications on iOS 10.0+ 
    UNUserNotificationCenter.Current.RequestAuthorization(
     UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, 
     (approved, error) => { }); 

    // Watch for notifications while app is active 
    UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate(); 
} 

Erstellen Sie eine Unterklasse UserNotificationCenterDelegate

public class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate 
{ 
    public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler) 
    { 
     // Tell system to display the notification anyway or use 
     // `None` to say we have handled the display locally. 
     completionHandler(UNNotificationPresentationOptions.Alert); 
    } 
} 
+0

Danke für Ihre Antwort, ich habe es bereits selbst behandelt. Was sollte hinzugefügt werden, wenn es im Hintergrund nicht funktioniert? –

+0

@ Passionate.C Der von Ihnen bereitgestellte Code sollte im Hintergrund funktionieren. –

Verwandte Themen