My Experiment with iOS Development

Last week I decided to experiment with iOS development. When I had started out learning Android development, it was not very difficult. Android programs are written in Java, which I have been using for many years and IDE used for Android development is Eclipse, which I have been using for many years now. All I had to get familiar was Android APIs.

However iOS development is very different for me. Applications are written in Objective-C, IDE is Xcode and they have to be developed on Mac platform using Cocoa framework. I have no experience with Objective-C, Xcode and Cocoa framework and have used Mac very little, only when I had to debug ColdFusion Builder issues specific to Mac. So I was not expecting smooth sailing; and I was not disappointed.

Setting up iOS development environment

The first task was to install Xcode. That was the easy part. Downloaded it from Apple Developer site. You need to have Apple Id to login and download Xcode .I wanted to develop a simple app quickly, using HTML, so I downloaded and installed PhoneGap too. With this I was able to quickly create a ‘Hello World’ app using Codova Application template (PhoneGap is renamed to Codova and it now an Apache project).

I was pleasantly surprised how quickly iPad simulator starts from Xcode. I have stopped using Android emulator on Windows because of its slow performance. Running my application in the simulator from Xcode was just one click and fast. Very impressive ! Then I wanted to run the same application on the iPad device. And that is when my problems began.

I was testing with iPad 2, which has iOS SDK 5. Whereas I had installed Xcode 3.2 (because I was using Mac 10.6 and the latest version of Xcode requires Mac 10.7). XCode 3.2 supports up to SDK 4. So Xcode 3.2 did not allow me to install the app on iPad. I thought downloading iOS SDK 5 and integrating it with Xcode would fix this problem. But I was surprised to find that you cannot download standalone iOS SDKs. You need to get it with Xcode. And to install Xcode 4 I had to upgrade Mac OS from 10.6 to 10.7. This upgrade is a reinstall and does not update existing version of Mac OS.

After upgrading Mac to 10.7 and Xcode to 4, I thought I could now transfer my app from Xcode to iPad. But then I found that you need Apple developer account to do this. And Apple developer account costs $99 per year for individual developer. Coming from completely free Android development and testing environment, this was shocking for me. To to test you applications on your own iPad, you need to spend $99 per year, and I am not talking about deployment to Apple App Store.

Since I am not yet serious about iOS development, I did not create Apple developer account and instead decided to test my app in the Simulator.

To summarize, following are good things about iOS devolvement environment

  1. Easy installation, build and deployment process
  2. Super fast Simulator

Bad things are –

  1. You development environment is very tightly controlled by Apple. You may have to upgrade the OS to use the latest iOS SDK.
  2. Local testing on you own device is not free.

 

Different Objective-C syntax and terminologies

Having come from Java/C++ world, I found the syntax and terminologies used in Objective-C mind bending. It is said to be extension of C language with OO syntax similar to Small Talk.

In Objective-C, you don;t call ‘method’ on an object, but you send a ‘message’ to the object or class. The message syntax is

[objectInstance param1:value1 param2:value2]

Note that the syntax includes square brackets at the beginning and end. Calling nested messages could make the code quite unreadable because of this syntax.

Method (or message) definition in the class starts with either + (meaning its a static method) or – (meaning it is an instance method). This is how complete message definition looks like

- (Return_Type) mentodNamePart1 : (param1Type) param1
                methodNamePart2: (param2Type) param2 {

  }

As you can see above, method name can be split into different parts, with each part taking its own parameters.

Like in C++, class definition and implementation are in different files in Objective-C. Definition is in the header file (.h) and implementation is in a file with extension .m. However, unlike C++, class definition starts with keyword ‘interface’. So to define Person class in Person.h, you will have to write

@interface Person : NSObject {
 // class member variables here
}
//class message/method definition here
@end


Since ‘interface’ keyword is used for class definition, actual interface (as in Java) is defined with keyword ‘prototype’.

@property keyword is used to define class member variables in header file. This generates implicit getter and setter functions. But this is a two step process. After defining property in the header file, you will have to ‘synthesize’ it in the implementation file (for each property) e.g.

@synthesize property1, property2

I really could not understand the need to synthesize it in the implantation file, after defining it in the header file.

What we call closure in JavaScript or CFML is called Block in Objective-C. And you define it as –

returnType (^blockName) (param1Type, param2Type);

So as you can see above, if you are coming from Java or C++ programming background then getting used to Objective-C syntax and terminologies could take some getting used to.

You can find more information about Objective-C syntax at Apple’s developer site.

Issues with recording audio with PhoneGap on iOS

The most difficult issue I am facing right now is recording audio using PhoneGap’s Media APIs on iOS. I have a PhoneGap application that records audio and which works fine on Android. I wanted to test the same on iOS. I am using the latest PhoneGap build, 1.6.1. For the same code that works on Android, I get following error on iOS –

ERROR: Method ‘create:withDict:’ not defined in Plugin ‘Media’

I have tried many things, including specifying url of the file with “document://”, creating file with File APIs before passing it to Media function, but none has worked. Media plugin is mapped to CDVSound class in PhoneGap’s iOS implementation and I could not find createWithDict method in this class. I have found that Media class is the most difficult to use in PhoneGap. Even in Android, there are some quirks of this API that you need to be aware of to successfully use it.

All in all, the experiment of learning iOS programming was not very pleasant. But I have not given up. Set-up and language issues are just initial problems that could be easily overcome. The next tasks are to be familiar with Cocoa framework and develop some simple native applications. But with the number of other projects I am working on, learning iOS is going to be a long-term endeavor.

-Ram Kulkarni

3 Replies to “My Experiment with iOS Development”

  1. Simply wish to say your article is as astonishing. The clearness in your post is simply nice and i can assume you are an expert on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please keep up the enjoyable work.

Leave a Reply

Social