如何从应用启用/禁用推送通知? [英] How to enable/disable push notification from the app?
本文介绍了如何从应用启用/禁用推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用中,我想从我的应用程序本身的设置页面启用/禁用推送通知。任何人都可以建议我从应用程序打开/关闭通知中心的应用程序状态的解决方案吗?
In my app I want to enable/disable push notification from the settings page of my app itself.Can any one suggest me a solution to turn on/off the status of app in notification center from the app ?
推荐答案
您可以使用以下代码注册和取消注册远程通知。
you can register and unregister the remote notification with bellow code.
注册RemoteNotification with bellow code..means启用通知
Register RemoteNotification with bellow code..means Enable notification
//-- 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)];
}
并使用以下代码禁用它。
and Disable it with bellow code.
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
这篇关于如何从应用启用/禁用推送通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文