如何启用/禁用来自应用程序的推送通知? [英] How to enable/disable push notification from the app?

查看:25
本文介绍了如何启用/禁用来自应用程序的推送通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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..意味着启用通知

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆