[AC-870] iOS 7 - registerForPushNotifications does not trigger success or error event
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Not Our Bug |
Resolution Date | 2014-11-18T23:47:34.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | 3.4.0, 3.4.1, ios7, pushnotification |
Reporter | Tim Varney |
Assignee | Radamantis Torres-Lechuga |
Created | 2014-11-18T17:22:18.000+0000 |
Updated | 2016-03-08T07:37:10.000+0000 |
Description
The following code does not result in a registration for push notification services on devices running iOS 7.1.
if (Ti.Platform.name == "iPhone OS" && parseInt(Ti.Platform.version.split(".")[0]) >= 8) {
// placeholder
} else {
// For iOS 7 and earlier
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;
alert('success');
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
Upon further inspection, this is not a problem with the titanium implementation of APN. It was a problem with my code. http://docs.appcelerator.com/titanium/3.0/#!/guide/Subscribing_to_push_notifications
FYI, the sample code on http://docs.appcelerator.com/titanium/3.0/#!/guide/Subscribing_to_push_notifications will not work for iOS 7. It is attempting to call the deviceTokenSuccess function before it is defined.