0

I am trying to use push notifications on the iphone emulator, but I am not having any success, I am using the example code:

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) {
Ti.API.log("identificada versão 8");
// Wait for user settings to be registered before registering for push notifications
Ti.App.iOS.addEventListener('usernotificationsettings', function registerForPush() {
    Ti.API.log("Notifications config set");
    // Remove event listener once registered for push notifications
    Ti.App.iOS.removeEventListener('usernotificationsettings', registerForPush); 

    Ti.Network.registerForPushNotifications({
        types : [Ti.App.iOS.NOTIFICATION_TYPE_BADGE, Ti.App.iOS.NOTIFICATION_TYPE_ALERT, Ti.App.iOS.NOTIFICATION_TYPE_SOUND],
        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
  });
}
// Process incoming push notifications
function receivePush(e) {
  alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
  deviceToken = e.deviceToken;
  subscribeToChannel();
}
function deviceTokenError(e) {
  alert('Failed to register for push notifications! ' + e.error);
}

and none of the registerForPushNotifications() callbacks are being fired, the success, the error, or the callback are not being called, and I am having a hard time solving it, I searched a bit on the web, the solutions where:

  • to turn off the liveView, but it did not solve my problem,

  • testing on a real iphone didn't help;

  • Check all the pushnotifications configurations on the appcelerator dashboard, and everything was fine.

I still can't find a solution.

Fokke Zandbergen
  • 3,866
  • 1
  • 11
  • 28

2 Answers2

4
  1. Push notification only works on device.Push Notifications iOS simulator

  2. Configuring push services for iOS devices

Community
  • 1
  • 1
Jagu
  • 762
  • 7
  • 17
  • it saved me a lot of time, now I am trying with a real ipad, and I receive the push, but still the push notification does not have a button on iOS, and on android the reply button does not fire any event. – Ricardo Gimenes Ferreira May 09 '16 at 13:19
2

As suggested by Jagu and Danny, there is no way to test the Push Notifications on simulator/emulator.

But also remember to turn off LIVE VIEW when you test it on physical device, otherwise you may not get device token.

Prashant Saini
  • 3,539
  • 1
  • 10
  • 24