Wednesday, May 15, 2013

Day 21: Google I/O

I am writing this post while waiting for the keynote to begin at Google I/O 2013.

In anticipation of the largest Android event of the year, I've temporarily switched back to my Nexus 4 from the iPhone 5. Originally I considered sticking with the iPhone this week as a true test of my commitment to this experiment but ultimately decided I didn't want to miss out on any Android goodness while here.

What has been surprising here at the Moscone Center is the number of iPhones I see being used by attendees and the number of developers I've spoken with who work on both Android and iOS. Perhaps dual specialization as a mobile developer is not as uncommon as it once was.

Well the keynote is about to begin. In typical conference fashion the wi-fi here is barely functional so I'll have to post this later.

Update:

Posted from my new Chromebook Pixel. Thanks Google!

Wednesday, May 8, 2013

Day 14: TDD

I have been a long-time proponent of the principles and benefits of Test-Driven Development. All of my Android projects use Robolectric and the built-in instrumentation testing framework. So naturally, when I decided to explore iOS, testing was one of the first things I wanted to investigate.

Fortunately there is no shortage of quality testing frameworks for iOS. I decided to focus my efforts on 3 of the available frameworks:

OCUnit

Based on the SenTest framework, OCUnit is a traditional xUnit style unit testing tool that comes bundled with the iOS SDK.

Kiwi

An RSpec style testing tool with an extensible expectation syntax and built-in mocking tools for Behavior-Driven Development (BDD).

KIF

A fully automated functional testing tool that simulates user interactions by leveraging accessibility attributes provided by the OS.


Three the Hard Way (HelloTDDiOS)


Three the Hard Way is a sample application I created to showcase all 3 testing frameworks in action. The app itself is very simple but provides a good forum for experimenting with various testing techniques.

Based on Your first iOS App tutorial on Apple Developer, Three the Hard Way allows you to enter a name via text input, click a button, and view the resulting greeting.

       


Development of the app was 100% test-driven using OCUnit. Below is an example of tests written to exercise the button callback in the view controller.

And the production code that was written to satisfy these tests. Notice how the tests use an instance of MockHelloTDDViewControllerDelegate to test the view controller in isolation rather than GreetingFactory (the actual delegate used in production).

And here are the same tests rewritten using Kiwi.

Finally, here is the end-to-end integration test using KIF that tests the button through a scripted UI interaction.

In order for KIF to locate the UI elements, we must set the accessibility labels in (void)viewDidLoad.

Fork the full project at https://github.com/ecgreb/Three-the-Hard-Way. Feedback is welcome.

Monday, May 6, 2013

Day 12: Battery Life

Standby Battery Life

This weekend I didn't charge my iPhone 5 from the time I left work on Friday afternoon until Sunday night when I went to bed. And I still had 17% battery remaining. That is rather impressive.

Granted I did not use my phone very much as it was beautiful outside and I spent most of the weekend power washing and applying joint sand to my brick patio. This is not a scientific study, but in my experience the standby battery life of my iPhone is much better than what I have had on any Android device (and I've had a lot of them).

Background Sync

Again, we are talking about battery consumption during times of sparse usage here. I can only assume one of the reasons for the iPhone's strong standby battery life comes from the fact that very little is happening when the device is idle. Apple does not allow third party applications to spin up long-lived background services with a few exceptions like Android does.

There is a tradeoff here. When I receive an APN to let me know I have a new message in GMail I can even read a preview of the message in the notification. But then when I open the GMail app to read the rest of the message it's not there. I have to wait for the app to sync with the server. With Android, the new message would already be there. And not just for Google apps-- any app can take advantage of background sync using a Service.

For me the extra standby battery life is not worth the time I have to wait each time I open an app for it to fetch fresh data from the server. In this age of on-demand computing it should already be there.

What do you think?

Thursday, May 2, 2013

Day 8: Provisioning Profiles

Steps required to install and run a development build of an Android app on a local device:
  1. Open Settings > Developer options menu on the device and check the box for USB Debugging.*
  2. Build and launch your app using Eclipse, IntelliJ, Ant, Maven, or Gradle.
  3. There is no step 3.
* On newer devices running Android 4.2 or later, if the Developer options menu is not visible go to Settings > About phone and tap the build number 7x to enable developer options.



Steps required to install and run a development build of an iOS app on a local device:
  1. Create an Apple ID at https://developer.apple.com/register.
  2. Register for the iOS Developer Program ($99) or join an existing iOS Enterprise Developer Program account (via email invite).
  3. Complete account creation and fill out professional profile.
  4. Sync your device with a computer using iTunes.
  5. Add your device to the Member Center using Xcode Organizer tool.
  6. Create a Certificate Signing Request (CSR) using Keychain Access utility.

             

  7. Upload the CSR to the Member Center and generate a signed certificate (requires admin access).
  8. Download the signed iPhone Developer certificate and install it in Keychain Access.
  9. In the Member Center, check the active iOS Provisioning Profiles for development. If there is an active development profile managed by XCode, you should be able to refresh the Provisioning Profiles in Xcode Organizer to automatically update to include the new development certificate. If not, or if the existing profile fails to update (as it did for me), proceed to step 10.

             

  10. Create a new iOS Provisioning Profile for Development. Be sure to include the iPhone Developer certificate you just created and your device in the profile.
  11. Download the new Provisioning Profile and drag it into the iTunes Library panel.

            

  12. Sync your device with iTunes to install the new Provisioning Profile.
  13. Build and launch your app using Xcode or (in my case) AppCode.
Just a bit more complex that what I have been used to with Android. My actual process involved many more steps of trial and error before I was able to distill it down to this (streamlined?) version.

If you are new to iOS like me... hopefully this guide will save you some time and frustration.

If you are a seasoned iOS developer... isn't there a better way!?