From the newest example on git hub (https://github.com/urbanairship/phonegap-ua-push), with a shinny new build of Phonegap/Cordova's latest v2.3.0, we're having trouble on iOS registering a device with UA. We had no problem until we updated to the latest. We're registering the device like this:
function on_reg(error, pushID) {
console.log("UA Registration complete.")
}
push = window.pushNotification
push.registerEvent('registration', on_reg)
But every time we call that code, we get an error that says "Device token is nil. Registration will be attempted at a later time". Except that never happens.
Here is the log:
2013-01-09 17:38:29.378 Grouped[271:907] [D] -[UAPush updateRegistration] [Line 589] Checking registration state
2013-01-09 17:38:29.380 Grouped[271:907] [D] -[UAPush updateRegistration] [Line 609] Device token is nil. Registration will be attempted at a later time
2013-01-09 17:38:29.744 Grouped[271:907] [D] +[UAKeychainUtils getDeviceID] [Line 275] Retrieved device id info from keychain.
2013-01-09 17:38:29.745 Grouped[271:907] [D] +[UAKeychainUtils getDeviceID] [Line 279] Device ID result is not nil.
2013-01-09 17:38:29.746 Grouped[271:907] [D] +[UAKeychainUtils getDeviceID] [Line 288] Loaded Device ID: C1E75722-ED34-4513-BBA5-CB9EDEBBD117
2013-01-09 17:38:29.747 Grouped[271:907] [D] +[UAKeychainUtils getDeviceID] [Line 289] Loaded Model Name: iPhone4,1
2013-01-09 17:38:32.724 Grouped[271:907] [D] -[UAAnalytics requestDidSucceed:response:responseData:] [Line 461] Analytics data sent successfully. Status: 200
What are we doing wrong?
I tracked this bug down to a change that was made in the newest version of PhoneGap:
For iOS, device.platform used to return “iPhone”, “iPad” or “iPod Touch” — now it returns (correctly) “iOS”.
This was conflicting with the PushNotification.js module, returning false information:
// Registration
PushNotification.prototype.registerForNotificationTypes = function (types, callback) {
if(device.platform == "iPhone" || device.platform == "iPad" || device.platform == "iPod touch") {
this.call_native(callback, "registerForNotificationTypes", [types])
}
}
Changing this to device.platform == "iOS" fixes the problem.
Urban Airship, if you want to update your git at https://github.com/urbanairship/phonegap-ua-push/blob/master/ios-sample/www/lib/PushNotification.js I'm sure many people would appreciate it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With