当用户拒绝推送通知时,Titanium推送通知ios错误回调似乎没有触发

时间:2016-05-04 23:41:09

标签: apple-push-notifications appcelerator appcelerator-titanium

Titanium 5.2.2 Appcelerator Studio 4.5.0 iOS 9.0 设备iPhone SE

当用户拒绝推送通知时,不会触发任何回调。这不幸地阻止了用户流。有人找到了解决这个问题的方法吗?

function registerForPushNotifications(callback){
var deviceToken = null;
// Check if the device is running iOS 8 or later
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {

    // Wait for user settings to be registered before registering for push notifications
    Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {

        // Remove event listener once registered for push notifications
        Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 

        Ti.Network.registerForPushNotifications({
            success: deviceTokenSuccess,
            error: deviceTokenError,
            callback: receivePush
        });
    });

    // Register notification types to use

    Ti.App.iOS.registerUserNotificationSettings({
        types: [
            Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND,
            Ti.App.iOS.USER_NOTIFICATION_TYPE_BADGE
        ]
    });

    // Process incoming push notifications
    function receivePush(e) {
        alert('Received push: ' + JSON.stringify(e));
    }

    // Save the device token for subsequent API calls
    function deviceTokenSuccess(e) {
        Ti.API.info("Registered for push notifications");
        deviceToken = e.deviceToken;
        callback(deviceToken);
    }

    function deviceTokenError(e) {
        alert('Failed to register for push notifications! ' + e.error);
        callback();
    }

}

}

1 个答案:

答案 0 :(得分:1)

如果用户拒绝激活Push,则不会触发推送回调。

通过'这会阻止用户流“,如果您的意思是您已经编写了代码,只有在设备成功注册Push时才能进一步运行,那么我想建议您放置将代码推送到单独的文件或函数中,并使剩余的应用程序代码独立于推送代码。

要知道您的设备是否已成功注册Push,我建议您使用变量,因为您永远不能依赖Push代码来运行所有剩余的应用代码。

如果您的意思是其他内容,请分享更多信息。感谢