IOS appcelerator 上的推送通知问题

IOS push notification issue on appcelerator

我的 IOS 应用程序有一个大问题。我按照 appcelerator 文档提供的指南设置我的 iOS 推送通知。一切似乎都很好,在我的 appcelerator 仪表板上,我在设备部分下看到我的设备使用其令牌注册,当我发送有关详细信息推送的推送通知(在推送通知日志中)时,我读取了我的 ID 设备号,并取得了完美的成功( 1).

但是在我的设备上我没有收到任何通知。我尝试打开我的应用程序并关闭我的应用程序,但没有任何显示。我不知道为什么会这样。在我的 android 上一切正常。这是我的代码:

//PUSH NOTIFICATION
var Cloud = require("ti.cloud");
//controllo se ho un token
var deviceToken = Ti.App.Properties.getString("deviceToken");

if ( deviceToken == "" || deviceToken == null) {
    requireToken();
} else {

    if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
        subscribeToChannel(deviceToken);
    }

}

//chiedo un token
function requireToken() {

    // Check if the device is running iOS 8 or later
    if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
     Ti.API.warn( "entrato nella versione" )
        // 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
            ]
        });

    }

    // For iOS 7 and earlier
    else {

        Ti.Network.registerForPushNotifications({
            // Specifies which notifications to receive
            types: [
                Ti.Network.NOTIFICATION_TYPE_BADGE,
                Ti.Network.NOTIFICATION_TYPE_ALERT,
                Ti.Network.NOTIFICATION_TYPE_SOUND
            ],
            success: deviceTokenSuccess,
            error: deviceTokenError,
            callback: receivePush
        });

    }

    function deviceTokenSuccess(e) {
        Ti.API.warn( "token ricevuto" )
            Ti.App.Properties.setString("deviceToken", e.deviceToken);
        subscribeToChannel(e.deviceToken);
    }
    function deviceTokenError(e) {
       //error action
    }

}

//controllo se sono iscritto alle notifiche push
if ( Ti.App.Properties.getString("subscribed") !== "true" ) {
    subscribeToChannel(deviceToken);
}


function subscribeToChannel (_deviceToken) {
        Ti.API.warn( "subscribe fatta" )
    Cloud.PushNotifications.subscribeToken({
        device_token: _deviceToken,
        channel: "ios_alerts",
        type: Ti.Platform.name == 'android' ? 'android' : 'ios'
    }, function (e) {
        if (e.success) {
                Ti.App.Properties.setString("subscribed", "true");
        }
    });

};

function receivePush(e) {
    Ti.API.warn("alert ricevuto" + JSON.stringify(e) )
    alert(e)
}

可能与您在 Apple 面板上的证书有关。 检查您是否使用您的 appid 启用了 APS,如果没有,激活它,然后生成另一个配置文件和 re-build 应用程序。 您还必须在 Appcelerator 平台网站上放置一个 .p12 文件。

以防万一这是您的问题:

  1. 如果设备处于调试模式,则无法获取设备令牌,必须处于 运行 模式!
  2. 请记住,在 ad-hock 下发布推送通知必须使用沙箱 'gateway.sandbox.push.apple.com'

克里斯

参考:https://archive.appcelerator.com/question/148135/no-reply-from-tinetworkregisterforpushnotifications