推送通知ON或OFF的iOS检查 [英] Push Notification ON or OFF Checking in iOS

查看:462
本文介绍了推送通知ON或OFF的iOS检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想如果应用程序(从恢复模式或开启)运行检查iOS设备的推送通知选项,任何时候。我用下面的code来检查,如果该选项为OFF:

I want to check "Push Notification option" in iOS device, any time if the application is running (or ON from resume mode). I use the following code to check, if the option is OFF :

-(void)PushNotificationServiceChecking
{
    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

    if (types == UIRemoteNotificationTypeNone)
    {
        NSString *msg = @"Please press ON to enable Push Notification";
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Push Notification Service Disable" message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"ON", nil];
        alert.tag = 2;
        [alert show];
    }
}

然后我手动使用下面的code换去的设置选项卡>>通知中心,使用户可以在其上:

Then i use the following code for going to the "Settings tab >> Notification center", so that user can on it manually :

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag == 2)
    {
        if (buttonIndex == 0)
        {
            // this is the cancel button
        }
        else if (buttonIndex == 1)
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];
        }
    }

}

不过,现在我面临的问题是,它只出现在第1次启动应用程序之后。它的工作原理是我想要的。但在那之后,如果我关掉从设置中的推送通知选项它给了我没有警报消息。我怎样才能实现呢?如果任何人有任何想法,请与我分享。
- 在先进的感谢

But, now the problem that i am facing is, it only appears at the 1st time after launching the application. It works as i want. But after that, if i turn OFF the "Push Notification option" from "settings" it gives me no "Alert Message". How can i implement this? If any one have any idea, please share with me. - Thanks in advanced.

推荐答案

如果在App一旦得了注册的 registerForRemoteNotification ,那么你可以禁用和启用。一旦你关闭,你要重新Regigister它,那么这将使 registerForRemoteNotification ,没有弹出一个警告。

If the App once got registered with the registerForRemoteNotification, then you can disable as well as enable . Once you disable and you are about to Re-Regigister with it, then this will enable the registerForRemoteNotification, without Popup for a alert.

技术说明TN2265:疑难解答推送通知

第一时间推送通知,iOS的启用推的应用注册
  询问用户是否他们希望收到通知的应用程序。一旦
  用户响应此警报就不会再次除非psented $ P $
  该设备恢复或应用程序已被卸载了至少
  一天。

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

如果要模拟你的应用程序的第一次运行,你可以离开
  卸载了一天的应用程序。您可以实现后者不
  实际上通过设置系统时钟转发天的等待一天或
  更多的,完全关掉设备,然后打开设备背面
  上。

If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.

富勒更多信息:<一href=\"http://stackoverflow.com/questions/8033216/how-to-show-would-like-to-send-you-push-notifications-alert-view-again\">INFO &功放;&安培; 信息2

Fore More Info: INFO && Info 2

修改:对于警惕检查启用 -

使用

 if (types & UIRemoteNotificationTypeAlert){} 

而不是

if (types == UIRemoteNotificationTypeNone){}

编辑:
从<一个最新的更新href=\"https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/#//apple_ref/occ/instm/UIApplication/isRegisteredForRemoteNotifications\">doc适用于iOS 8或更高版本,您可以查看:

- (BOOL)isRegisteredForRemoteNotifications

这篇关于推送通知ON或OFF的iOS检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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