我正在使用Distriqt推送通知扩展,如果用户在第一次运行时不允许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吗?它什么时候会变成假的?我该如何处理这种情况呢?
发布于 2016-02-18 23:46:57
我发现了我的应用程序中发生了什么:
我正在处理激活/停用事件来启用和禁用后台执行:NativeApplication.nativeApplication.executeInBackground = true;。这使得您的应用程序能够在后台运行,忽略请求用户权限的UI,并且在安装后第一次运行时PushNotifications.service.isEnabled为true。
我所做的就是延迟添加激活和停用侦听器,直到其中一件事情首先发生:
当设备接收推送令牌失败时,设备不支持推送通知PushNotifications.isEnabled == false
我希望这对某些人有帮助。
发布于 2016-02-22 07:26:31
对于任何其他对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 );
}https://stackoverflow.com/questions/35482520
复制相似问题