Notifications Xam.Plugins.Notifier在IOS 11上不工作

Notifications Xam.Plugins.Notifier在IOS 11上不工作,notifications,xamarin.ios,xamarin.forms,Notifications,Xamarin.ios,Xamarin.forms,我正在使用Xam.Plugins.Notifier包在Xamarin.Forms项目中实现本地通知 下面是我在PCL项目中编写的代码。 CrossLocalNotifications.Current.Show(“标题”、“说明”) 它在Android上运行良好,但在IOS上不起作用。 我不确定它是否适用于较低的IOS sdk。 无论如何,它在IOS 11上不起作用 下面是我在AppDelegate.cs中添加的代码 if (UIDevice.CurrentDevice.C

我正在使用Xam.Plugins.Notifier包在Xamarin.Forms项目中实现本地通知

下面是我在PCL项目中编写的代码。 CrossLocalNotifications.Current.Show(“标题”、“说明”)

它在Android上运行良好,但在IOS上不起作用。 我不确定它是否适用于较低的IOS sdk。 无论如何,它在IOS 11上不起作用

下面是我在AppDelegate.cs中添加的代码

            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);
            }
有人能帮我修一下吗? 我想让这个软件包在IOS上运行


谢谢。

哪种情况不起作用?活动还是背景

如果它处于活动状态时不工作,您可能会忘记处理委托(子类
UNUserNotificationCenterDelegate

按如下方式修改您的代码:

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();
}
创建一个子类
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);
    }
}
公共类UserNotificationCenterDelegate:UnuseNotificationCenterDelegate
{
public override void WillPresentNotification(未使用通知中心、未通知通知通知、操作完成处理程序)
{
//告诉系统以任何方式显示通知或使用
//“没有”,也就是说我们已经在本地处理了这次展览。
completionHandler(UNNotificationPresentationOptions.Alert);
}
}

哪种情况不起作用?活动还是背景

如果它处于活动状态时不工作,您可能会忘记处理委托(子类
UNUserNotificationCenterDelegate

按如下方式修改您的代码:

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();
}
创建一个子类
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);
    }
}
公共类UserNotificationCenterDelegate:UnuseNotificationCenterDelegate
{
public override void WillPresentNotification(未使用通知中心、未通知通知通知、操作完成处理程序)
{
//告诉系统以任何方式显示通知或使用
//“没有”,也就是说我们已经在本地处理了这次展览。
completionHandler(UNNotificationPresentationOptions.Alert);
}
}

谢谢你的回复,我已经亲自处理了。如果在后台不工作,应该添加什么。@激情.C您提供的代码应该在后台工作。谢谢您的回复,我已经自己处理过了。如果在后台不起作用,应该添加什么。@periomic.C您提供的代码应该在后台起作用。