Appcelerator 上的 registerForPushNotifications() 没有回复

No answer from registerForPushNotifications() on Appcelerator

我正在尝试在 iphone 模拟器上使用推送通知,但没有成功,我正在使用示例代码:

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);
}

和none的registerForPushNotifications()回调被触发,成功,错误,或者回调没有被调用,我很难解决它,我搜索了一下网络,解决方案,其中:

我仍然找不到解决方案。

  1. 推送通知仅适用于设备。Push Notifications iOS simulator

  2. Configuring push services for iOS devices

正如 Jagu 和 Danny 所建议的,无法在 simulator/emulator 上测试推送通知。

但也记得在实体机上测试时关闭LIVE VIEW,否则可能得不到device token。