首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Distriqt通知扩展:如何知道用户是否在第一个应用程序运行时不允许PNs?

Distriqt通知扩展:如何知道用户是否在第一个应用程序运行时不允许PNs?
EN

Stack Overflow用户
提问于 2016-02-18 21:15:42
回答 2查看 203关注 0票数 0

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

我执行以下操作:

代码语言:javascript
复制
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吗?它什么时候会变成假的?我该如何处理这种情况呢?

EN

回答 2

Stack Overflow用户

发布于 2016-02-18 23:46:57

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

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

我所做的就是延迟添加激活和停用侦听器,直到其中一件事情首先发生:

当设备接收推送令牌失败时,设备不支持推送通知PushNotifications.isEnabled == false

  • When

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

票数 0
EN

Stack Overflow用户

发布于 2016-02-22 07:26:31

对于任何其他对isEnabled标志有问题的人,请在这里发布这篇文章:

代码语言:javascript
复制
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 );
}

原文来源:https://gist.github.com/marchbold/fb0438cf326a44cea0cf#file-distriqt-extensions-pushnotifications-isenabled-as

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35482520

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档