Thursday, August 7, 2014

Mobile Development with Cordova (Phonegap): Afterword

I'd like to again thank GreenInfo Network, my generous employers, for giving me the time to learn, then giving me the okay to share the knowledge. Those 13 chapters are a distillation of real-world pitfalls and techniques, beyond the copy-and-paste world of books. I hope it helps. :)

Mobile Development with Cordova (Phonegap): Appendix C

Appendix C: Phonegap Build

Phonegap was originally an Adobe project -- and still is, Cordova is the open source version. Phonegap Build is a service provided by Adobe, to simplify the process of compiling your apps.
 
Simply put, you upload a ZIP file containing your www content (HTML, JS, CSS files, jQuery, et al) and simply upload it to the PGB website. They will then build the app for iOS, Android, and other platforms. This takes a lot of the overhead out of development, since you don't need a Mac, Xcode, Apache ant, a local copy of Cordova, etc.

But it's not a panacea:

  • You do still need a Mac in order to use the Keychain Access program, to generate certificates and to convert certificates into the P12 format required by Phonegap Build.
  • There is a limit of 10 MB of content in the ZIP file. This is quite generous for some apps, but our apps tend to include JSON and GeoJSON databases, pushing them over the limit or not leaving comfortable space for growth. There are techniques for downloading the database file over the network and storing on disk, so it doesn't need to be bundled with the ZIP file. But those are more complicated, and not as "zero maintenance" as simply bundling data that won't change except between versions.
  • The cycle of waiting tends to be several minutes. Using local builds on the Mac, I can have turnarounds in 60 seconds on the iPad. On Android, I need to transfer and download the APK, which is ultimately about as time-consuming as the Build service.
  • Android apps built in the PhoneGap Build, will not run in singleTop mode. This means that any time someone leaves the app, then resumes it by tapping the icon, it starts all over again starting with the splash screen and then the welcome page. This has been a reported bug for two years...




Because of these limitations, we don't use it anymore. But it certainly bears mention in any publication on the topic of PhoneGap and Cordova.


Tuesday, August 5, 2014

Mobile Development with Cordova (Phonegap): Appendix B

Appendix B: Generating a Provisioning Profile (iOS)

Your Apple developer career is managed by the Provisioning Portal. As described earlier, your key components are:
  • A developer certificate
  • An app ID, which is simply a logical grouping of applications
  • A list of devices for beta testing
  • A provisioning profile linking all of these together
Getting started:
  • Log in to the Provisioning Portal
    https://developer.apple.com/
  • Go into Certificates, Identifiers & Profiles
    If you don't already have a Certificate, generate one and load it onto your Mac.
    Make it a Production certificate, for "App Store and Ad Hoc"
  • Defined an App ID.
    The simplest choice here is to make a wildcard matching your organization, e.g. org.greeninfo.* Using a wildcard will allow this provisioning profile to match multiple apps, as long as they start with org.greeninfo
  • Enter the UDIDs for your beta tester devices
    Again, only devices listed here AND chosen for a Provisioning Profile can effectively beta test.
  • Generate a Provisioning Profile
    Tie together your developer identity, your app, and those devices, into a single logical grouping.
When you're setting up your mobile app, you'll define a Team in Xcode, and Xcode will download your certificate and Provisioning Profile for you. You will find yourself doing this relatively often as project momentum builds and beta testers want to come on board. You will need to regenerate a provisioning profile and downloaded into Xcode every time. See the chapter about beta testers for more info.

Do not forget the 100 device limit. If you're doing apps for 5 or 6 companies, and each one wants 20 people to check out the app, you could run out of slots.
 
 

Monday, August 4, 2014

Mobile Development with Cordova (Phonegap): Appendix A


Appendix A: Generating a Certificate Keystore (Android)

Android apps must have a digital signature. For Android, you generate your own certificate, which is saved inside a "keystore" file. You generate this with the keytool command-line tool, which is part of the Android SDK you downloaded while setting up your build environment.


Generating a Keystore

The command below generates an Android keystore named android_certificate.keystore containing a single certificate named android, good for about 25 years (10,000 days), and with a nice large key size (8kB is current standard).
keytool -genkey -v -keyalg RSA -keysize 8192 -validity 10000 -keystore android_certificate.keystore -alias android

You will be prompted to enter a password, then for your "first and last name" which really means any identifier such as your company or department name, then other identifying info such as your location. Lastly you'll be asked for a second password to lock the keystore (as contrasted to the certificate itself) but I like to just use the same password for both.

In the end you'll have a keystore file. Back it up into a safe place along with the alias and password.

Warning: The certificate and keystore must be the same as you sign of future versions of the same app. If you lose the key store or forget the alias or the password, you will not be able to sign future versions of the app. The result is that anybody trying to upgrade, will fail: they will need to uninstall the previous version of the app before installing the upgrade.
 

Using the keystore in Cordova CLI Tools

An app compiled with cordova build android --release will not be properly signed and able to install onto phones, unless you instruct ant to use the keystore.

You can specify the path to the keystore file, as well as the alias, in the ant.properties file. This is described in the  Setting Up Certificates part of chapter 3 when setting up a new project.

Tip: I always use cordova build android --release so it prompts for a real certificate. This adds an extra step to the build/test cycle, but does ensure that the selfsame APK can be distributed to others (it's easy to forget, and send an APK that's not signed). It also ensures that I in fact have the keystore handy, as I am unlikely to lose it and then lose my backups over time, if I'm actively using it every day of development.



Saturday, August 2, 2014

Mobile Development with Cordova (Phonegap): Chapter 10

Chapter 10: Distributing the App to Stores

Once you've created your mobile app and tested it thoroughly, it's time to distribute it!
There are multiple avenues for distribution: the Apple App Store for iOS, and two major app stores for Android.

Android: Google Play

This is arguably the most popular of the app stores for Android.
Sign-up is based on the same Google account that you probably already use for Gmail or Google Docs.

https://play.google.com/apps/publish/signup/

On the Dashboard, use the "Publish an Android App on Google Play"

There are rather a lot of questions if you're establishing a new app, though many can be skipped if you're simply updating a new APK. The most time-consuming part is making up the rather large set of icons and screenshots. It took me about 45 minutes my first time.

Android: Amazon App Store

This is arguably the second most popular of the app stores for Android.
Sign-up is based on the same account that you already use for shopping at Amazon.com.

https://developer.amazon.com/public/

On the Dashboard, use the "Add a New App" wizard.

There are rather a lot of questions if you're establishing a new app, though many can be skipped if you're simply updating a new APK. The most time-consuming part is making up the rather large set of icons and screenshots. It took me about 45 minutes my first time.

iOS: Apple App Store

As in most of the steps previous, submitting to Apple's App Store is more complicated than for the Android stores, but then again also more polished in some ways.

As a quick overview, there are three steps to submitting an app to the store, once you're done testing it extensively.
  • Create an App Record in iTunes Connect (the web portal for managing App Store apps). This is only necessary if you're submitting a new app, not for upgrading an existing app.
  • Build an Archive of it (the IPA file) and sign it with a distribution Provisioning Profile intended for Store Distribution. In that same Archive operation, proceed to upload it to the App Store.
  • Wait for approval, or for an explanation of why the app was rejected.

Creating the App Record

Creating an App Record is just what it sounds like: creating the app's description, screenshots, etc.  Naturally, you only do this for a new app and not for every upgrade of the app.

This is done via the iTunes Connect website https://itunesconnect.apple.com/
Follow the Manage Your Apps option, and the Add New App button.
It's a tedious process like all the app stores, especially the need for various screenshots and splash screens.

Tip: Apple requires screenshots from a variety of devices, including an iPad, a 3.5" phone, and a 4" phone. As such, you and your beta testing team will need at least one of each of these devices. Apple is very clear that you cannot simply resize an existing image, and I have a feeling that they really are paying attention.



At this point, if you visit your app dashboard on iTunes Connect, you should see that it is waiting for upload.

Building and Uploading the Archive

Open up the Xcode project file, and make sure you have a physical device attached. The archive option will not be available, unless you have a physical device attached.

Go into Project/Archive, and follow the wizard same as you had when you are making Ad Hoc builds for your beta testers. But this time, select a Provisioning Profile intended for store distribution. Then simply walk through the wizard.

At this point, if you visit your app dashboard on iTunes Connect, you should see that it is waiting for approval.


Tip: You app record must be Waiting For Upload. If you already uploaded, but want to make a change, you must cancel your previous upload via the iTunes Connect website, which puts the app back into a Waiting For Upload state.



Approval

Apple is proud of their stringent testing process. I wasn't happy about it first, but I must admit that it's a good thing. They test on a variety of devices, and they make sure that your app isn't consuming the users' valuable iCloud space.

But keep at it, follow their instructions, and eventually you'll get through.