gpt4 book ai didi

c# - 检查通知权限是否被授予(Xamarin,iOS)

转载 作者:行者123 更新时间:2023-12-01 18:04:02 26 4
gpt4 key购买 nike

系统会提示用户拒绝/授予通知权限:

screenshot

该应用程序有一个设置 View ,用户可以在其中切换通知。如果未授予权限,我想将用户指向 iOS 设置(就像 WhatsApp 那样)。

如何检查权限是否被授予?特别是在用户授予权限但随后决定从 iOS 设置而不是在应用程序内部禁用它们的情况下。

有一个广受欢迎的permissions plugin遗憾的是,它不支持此特定许可。

最佳答案

您可以使用 DependencyService 检查应用程序是否启用了通知。

在iOS中:

[assembly: Dependency(typeof(DeviceService))]
class DeviceService : IDeviceService
{
public bool GetApplicationNotificationSettings()
{
var settings = UIApplication.SharedApplication.CurrentUserNotificationSettings.Types;
return settings != UIUserNotificationType.None;
}
}

在表格中:
public interface IDeviceService
{
bool GetApplicationNotificationSettings();
}

在这些之后,您可以从您的页面或 View 模型中调用您的 DependencyService,如下所示:
bool isNotificationEnabled = DependencyService.Get<IDeviceService>().GetApplicationNotificationSettings();

关于c# - 检查通知权限是否被授予(Xamarin,iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58915284/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com