【问题标题】:IOS push notification issue on appceleratorappcelerator 上的 IOS 推送通知问题
【发布时间】:2016-01-25 13:52:58
【问题描述】:

我的 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-push-notifications appcelerator appcelerator-titanium


    【解决方案1】:

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

    【讨论】:

    • 我尝试更改一些证书,但我没有解决任何问题。我怎么可能在我的 appcelerator 仪表板上看到成功,而没有证书的情况下通知不会到达我的设备上?
    • 好的,我删除了所有证书并重做所有,现在终于可以工作了!谢谢!
    【解决方案2】:

    以防万一这是您的问题:

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

    克里斯

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

    【讨论】:

      猜你喜欢
      • 2016-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      • 2017-01-22
      • 2019-01-25
      • 2014-05-24
      相关资源
      最近更新 更多