Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Urban Airship & Phonegap, can't register device: "Device token is nil"

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?

like image 315
Ryan Martin Avatar asked Jan 10 '13 02:01

Ryan Martin


1 Answers

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!

like image 64
Ryan Martin Avatar answered Sep 30 '22 06:09

Ryan Martin