gpt4 book ai didi

ios - 如何启用/禁用来自应用程序的推送通知?

转载 作者:IT王子 更新时间:2023-10-29 07:56:51 25 4
gpt4 key购买 nike

在我的应用程序中,我想从我的应用程序本身的设置页面启用/禁用推送通知。任何人都可以建议我一个解决方案来从应用程序的通知中心打开/关闭应用程序的状态吗?

最佳答案

您可以使用以下代码注册和注销远程通知。

用下面的代码注册RemoteNotification..意味着启用通知

//-- Set Notification
if ([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
// For iOS 8 and above
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
// For iOS < 8
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

并使用下面的代码禁用它。

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

关于ios - 如何启用/禁用来自应用程序的推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13814651/

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