Push notification Distriqt推送通知扩展:如何知道用户在第一次运行应用程序时是否不允许PNs?

Push notification Distriqt推送通知扩展:如何知道用户在第一次运行应用程序时是否不允许PNs?,push-notification,air,distriqt,Push Notification,Air,Distriqt,我正在使用Distriqt Push Notifications扩展,如果用户在第一次运行时不允许使用PNs,我将无法使其正常工作:应用程序将结束注册用户,因为它声明PNs已启用且可用 我做了以下工作: if (PushNotifications.isSupported()) { registerPushNotifications(); } private function registerPushNotifications():void { PushNotifications

我正在使用Distriqt Push Notifications扩展,如果用户在第一次运行时不允许使用PNs,我将无法使其正常工作:应用程序将结束注册用户,因为它声明PNs已启用且可用

我做了以下工作:

if (PushNotifications.isSupported()) {
    registerPushNotifications();
}

private function registerPushNotifications():void {
    PushNotifications.service.addEventListener(PushNotificationEvent.REGISTER_SUCCESS, onPushNotificationToken);
    PushNotifications.service.register(MODEL.Configuration.GCM_SENDER_ID);
}

private function onPushNotificationToken(event:PushNotificationEvent):void {
    if (PushNotifications.service.isEnabled) { registerDevice(); }
}

如果用户不允许,不
PushNotifications.service.isEnabled
应该为false吗?什么时候会变成假的?我应该如何处理这种情况?

我已经发现我的应用程序中发生了什么:

我正在处理激活/停用事件以启用和禁用后台执行:
NativeApplication.NativeApplication.executeInBackground=true。这使您的应用程序能够在后台运行,而忽略请求用户权限的UI,并且安装后第一次运行时,
PushNotifications.service.isEnabled
true

我所做的是延迟添加激活和停用侦听器,直到以下情况之一首先发生:

  • 设备不支持推送通知
    PushNotifications.isEnabled==false
  • 当设备收到推送令牌时
  • 当设备无法接收推送令牌时

我希望这对某人有所帮助。

只要把这篇文章贴在这里,就可以让任何对
isEnabled
标志有问题的人看到:

var hasRequestedPermissionsOnce:Boolean = false;
// You should load hasRequestedPermissionsOnce from some persistent storage, defaulting to false 

...

PushNotifications.init( APP_KEY );
if (PushNotifications.isSupported)
{
    if (PushNotifications.service.isEnabled)
    {
        // Notifications have been enabled by the user 
        // You are free to register and expect a registration success
        register();
    }
    else if (!hasRequestedPermissionsOnce)
    {
        // You should implement hasRequestedPermissionsOnce somewhere to check if this is the first run of the app
        // If we haven't called register once yet the isEnabled flag may be false as we haven't requested permissions
        // You can just register here to request permissions or use a dialog to delay the request
        register();
    }
    else
    {
        // The user has disabled notifications
        // Advise your user of the lack of notifications as you see fit
    }
}

...

private function register():void
{
    // You should save hasRequestedPermissionsOnce to a shared object, file or other persistent storage
    hasRequestedPermissionsOnce = true;

    PushNotifications.service.addEventListener( PushNotificationEvent.REGISTER_SUCCESS, registerSuccessHandler );
    PushNotifications.service.addEventListener( PushNotificationEvent.REGISTER_FAILED,  registerFailedHandler );

    PushNotifications.service.register( GCM_SENDER_ID );
}

这里的原始来源:

我考虑过使用超时,延迟注册,但它只会延迟特定时间的注册;如果用户在此期间未点击“允许”或“不允许”,它也将不起作用。您好,我们这里有一些示例代码来说明此功能的最佳用法:我已使用该代码检查应用程序是否第一次运行,但我在回答中说,我必须使用另一种方法,因为我启用了“在后台执行”,而
isEnabled
第一次返回true,忽略用户设置的内容(事实是用户还没有设置任何内容)。真的吗?更改execute标志不应影响远程通知的注册。所以,在您将该标志设置为“isEnabled reports true”之后,如果您将其注释掉,它将返回false?可能我遗漏了一些内容,但当
PushNotifications.service.register(GCM_SENDER_ID)时时,会出现一个弹出窗口,请求对推送通知的权限,有时,isEnabled会报告true,即使用户单击了“否”。幕后发生的情况是,
register
尝试为推送通知注册设备,并且当触发
registerSuccessHandler
时,
isEnabled
等于
true
,但用户单击了否。我想您使用了
haserequestedpermissionsonce
以避免
isEnabled
第一次为假,但这是真的,有什么更奇怪的。您在测试什么版本的iOS?我正在测试iOS 9.1。该版本上是否有报告的bug?