Using Appcelerator is great for quickly building useful mobile apps for both iOS and Android. However, implementing push notifications under each platform can be vexing. That’s where third party services like Pushwoosh and Urban Airship come in. They simplify the implementation to allow you to be up and running quickly. That is, unless you run into some weird setup error like
Urban Airship Autopilot: Failed to load meta-data
I recently inherited an Appcelerator project where I needed to implement Urban Airship. I naturally started by looking at the Urban Airship documentation for the Titanium platform. The documentation is straight-forward, and I was soon up and running and getting notifications on my iOS test device.
A quick note: You WILL NOT get notifications in the iOS simulator. You’ll need a development provisioning profile and will need to install the app on a physical device.
Firing up my Android emulator, I quickly ran into a problem:
Uncaught Error: Take off must be called before shared(). A bit more scanning of the log showed the initial error:
Urban Airship Autopilot: Failed to load meta-data, NullPointer: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
This error completely crashes the app. And the error message itself is not very useful. But I figured there was something I was missing in the Android manifest that was causing the
meta-data error. I scoured the documentation for any sort of information I might have overlooked. I googled every variation of the error and situation I could think of. I posted in the support forums. Nothing.
In desperation, I created a new project with the same application ID, and copied the code to the blank project. I launched the app in the emulator, sent a test push notification, and it worked. At this point I knew it there was something in the project I inherited that was causing the issue.
Digging a little deeper into the project, I realized it was using a custom
AndroidManifest.xml to keep the screen orientation locked to portrait. From there I guessed that the Urban Airship module needed to generate a
meta-data tag for the manifest, and the custom manifest was preventing that from happening.
Indeed, after I converted the custom manifest back into the
tiapp.xml, Urban Airship ran without a hitch. I was happy. The client was happy. And I’m sure the users will be happy when they get useful push notifications.