0
votes

i have a big problem on my IOS app. I follow the guide provide by appcelerator documentation to setup my iOS push notification. All seemed work fine, on my appcelerator dashboard i see under the device section my device registered with its token, and when i send a push notification on the detail's push (in push notification log) i read my id device number with a perfect Success(1).

But on my device i didn't receive any notification. I tried with my app opened and with my app closed, but nothing has showed. I don't know why this happen. On my android all work fine. Here my code:

//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)
}
2

2 Answers

0
votes

is probably something related to your certificates on Apple panel. Check if you enabled APS with your appid and if not, activate it, then generate another provisioning profiles and re-build the app. You will also have to put a .p12 file in the Appcelerator platform website.

0
votes

Just in case this is your issue(s):

  1. Device Token Cannot be fetched if on Device in Debug mode, must be in Run Mode!
  2. Remember that under ad-hock releases push notifications MUST use the sandbox 'gateway.sandbox.push.apple.com'

Chris

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