Showing posts with label iPhone SDK. Show all posts
Showing posts with label iPhone SDK. Show all posts

Monday, June 29, 2009

Apple iPhone: Light-Years Ahead

As shown in one of the banners at the Moscone West during WWDC 09: one year later, light-years ahead:

WWDC09.JPG


It could not be more true. Many things have changed during the last two years, and in the last year in particular.

I truly believe there is still no competitor for the iPhone. I have tested many different phones. I have owned, both Blackberry and Palm branded phones, and I have had several Nokia phones in the past. Being a mobile device fan, I have the tendency to ask people to show me their phones. I have seen many, and there is still no competition, not even in those new touch screen phones that keep popping up.

It is also my believe that the key to is not in the hardware, which is definitely good, but not unique. The key difference is in the software. Apple created a software base that is extremely responsive to user input, and that made it easy and intuitive. Then, with the SDK and the App Store, opened the door to rest of us.

P1000157.JPG


Many things have changed. From the initial 550 applications that were available on July 11th, 2008, the App Store has now surpassed the 50,000 mark. That is almost 100 times more applications, and still growing fast. Another change is the introduction of firmware 3.0. Technologies like MapKit or Core Data, are amazing. Finally, new hardware. Faster, with more memory and more powerful.

In my opinion, 2 years after the introduction of the iPhone, Apple clearly dominates the smartphone market and it is clear that its intention is to keep doing it. But what it is most impressive is, that Apple is listening to both customers and developers. Took a while, and there are still things Apple do not want to change, but they are doing it. Almost all my requests for new iPhone SDK APIs have been made available in firmware 3.0, and almost most of the common requested features are now there (like copy & paste). Even most of the changes I wanted on the App Store are there.

So, I want to take this opportunity to say: thanks, Apple! Thanks for the iPhone, for the SDK, for the App Store, for your updates, and most of all, for listening. Keep doing it, and you shall keep light-years ahead of the competition.

Tuesday, December 16, 2008

App Store: Try Before You Buy

Some time ago, I wrote about "The Cruel Economy of the App Store". This article was echoed in TUAW and Business Week, among other media. Since then, Apple has introduced several important changes that will improve both the developers' and the users' experiences:

- Different sorting options per category.
- Multiple screenshots available in the device when browsing the App Store.
- No voting / comments allowed for people who have not purchased or downloaded the application. This will prevent users from leaving destructive, uninformed comments that do not really help other users make purchasing decisions, nor the developer in crafting a better product.
- No shifting in category sorting when updates are released. This avoids confusion to the final users, as they always look at the latest released applications. In addition, it is no longer possible to trick the system with simple, unimportant updates whose main purpose was just to relocate the apps at the beginning of the list.

These changes are very much welcome, and I do believe they are steps in the right direction.

However, the improvements are not enough. The App Store is populating at a very fast rate. When it launched it had around 550 applications, whereas it hosts more than 10,000 today. That is, in only 4 months the number of applications is 20 times what it was at launch, and it continues to grow on a daily basis: according to AppShopper, around 100 apps are added every day.

This rapid growth is a challenge for all App Store stakeholders. First of all, for Apple: they need to manage, review and approve all the new apps and the corresponding update cycles in an efficient and consistent manner, doing so quickly and applying common criteria to similar cases. What's even more important, Apple is probably extremely interested in promoting high quality apps to keep their lead in the thriving mobile computing platform race and once again, they need to do it consistently and coherently to keep their independence. I would anticipate that one of the top priorities for Apple at this point should be to listen to developers' technical feedback, in order to identify potential extensions to the API, evolutions and other improvements. Keep in mind that one of the most anticipated new features in the API -the ability to receive push notifications- was announced long before it was ready, probably to respond to concerns from the developer community about the implications of not having such mechanism.

Developers also need to deal with such a rapid growth: they are seeing their apps drowned in a sea of apps from others, and it is becoming more and more difficult to differentiate their products in the eyes of the customers. Since users would choose what apps to buy based on just a simple description, a screenshot and a price tag, price soon became the single most important mechanism to market your app inside the App Store. As Craig Hockenberry pointed out, the problem now is that there's a strong tendency to lower prices all the way down to $0.99 - as a consequence, not even price will be enough to differentiate apps any more.

Lastly, users suffer from such a formidable response to the App Store in terms of uncertainty. It's fantastic to have literally dozens of competing apps for any interest area; however, users can only see a uniform, flat offer of similar apps with similar screenshots, similar descriptions and similar prices. It's thus becoming more and more difficult to ensure you buy the app that meets your needs the most, or the one you find easiest to work with, or the one that has those little details you love, or the one that launches faster, or the one you think is simply most beautiful.


Trying


There are many things that Apple can do to adapt to the new situation, helping users and developers at the same time. As they have already demonstrated, I'm sure they will be working on many areas of improvement; however, I would like to stress what we believe is the single most important missing feature in the App Store: a "try before you buy" mechanism.

Such a mechanism should be part, we believe, of the official SDK. It would allow developers to offer trial versions or trial periods for their products in a snap, since the App Store would handle the specifics of downloading, expiration checking and upgrading. Users would be able to list the applications in trial, with details about how many days there are left and what features (if any) would be disabled if the user chooses not to upgrade. The App Store would allow the user to purchase "the license" that would allow the application to be properly registered and keep operating normally thereafter.

This is a model that has been in place for many years in the shareware market, and is perfectly understood by consumers and developers. An additional advantage of implementing it in the App Store would be the coherence and consistency of the user experience - trial policies, once defined, will be shared by all apps.


Our experience - Sketches Trial


Since we are firm believers of this principle, we actually prepared and submitted a special "Sketches Trial" version to the App Store on October 18th. Unfortunately, it was rejected two weeks later, on the grounds that they could not accept our trial because "the application must be a fully functional app and cannot reference features that are not implemented or up-sell to the full version".

From our point of view, our concept was not in conflict with that. Our idea was simply to allow the user to try the application for a few days, without any limitations at all. After the trial period was over, the user could still use some of the features in Sketches, making it act more like a "Sketches Lite" version they would get for free.

Picture 1383.jpgPicture 1385.jpg


What surprised us the most is that the rejection email actually encouraged us to create a free Sketches Lite version, as many others do, but the trial concept was out of the question. What we don't understand is, why is it better to offer a "crippled" lite version, instead of a fully functioning one that some days later transforms into the same lite version? We are proud of the variety of features we've implemented in Sketches while maintaining the ease of use, and we'd like our prospective customers to see and try all of them - that's the only way they can fully evaluate and appreciate the usefulness of the product. In contrast, a "lite" version would necessarily offer a subset of the functionality, and therefore users would get the wrong idea about the capabilities of the product, or they would be constantly nagged about the limitations that do not exist in the full version. We believe those alternatives are clearly inferior.


The Road Ahead


We believe that the addition of a "try before you buy" mechanism would be a terrific improvement to the App Store, since it will encourage customers to try all the apps they want - hence, sales will be informed ones, satisfaction will be much higher and prices will be easier to match to product features. Our idea to offer our own trial mechanism was clearly an interim solution until Apple delivers global trial capabilities. They are in the perfect position to apply all the well-known shareware practices in a consistent, reliable and easy to use way, and we have no doubt they will be considering this improvement.

We'd like this blog post to be seen as a small contribution towards the improvement of an already awesome platform. If you, as a developer or a customer, agree with us, don't hesitate to express your comments or digg the story :)

Thursday, October 02, 2008

iPhone Programming Tips: building Unix software

The NDA that was part of the agreement between Apple and registered iPhone developers was lifted yesterday. Not an hour had gone by before other developers started to share tips, code or even full frameworks. Like them, we'd also like to contribute some of the learnings we've found during our work with Apple's SDK.

We've decided, therefore, to write a second piece in our internationally acclaimed iPhone Programming Tips series. Our first article, devoted to image orientation techniques, was written during our jailbreak apprenticeship, before the NDA even existed - how's that for anticipation?

This time we'll explore a very different area: how to build a Unix source package in such a way it can be used as part of your iPhone project.

The Problem



So you've found this wonderful open source Unix package that perfectly handles one of the areas you need in your application. Being a publicly scrutinized, well-maintained library, you decide you would waste your time if you tried to do something similar, so you try to use it in your project and concentrate on your own features. Or maybe you simply want to test how this thing would work in the iPhone. Whatever your reasons are, you download the distribution and read the INSTALL file. This package is so well designed it compiles under a zillion Unix variants, including many evolutionary dead ends. It includes a fancy "configure" script that guesses everything it needs to know to configure itself properly. Apple's Developer Tools include a full gcc/make toolchain, so you perform the sacred ritual "./configure; make" and presto, you obtain an Intel dynamic library ready for use!

Wait a minute, that's not what you need. You want to cross-compile for ARM so that it runs on the device, of course. And you need it to run in the simulator, too.

Being a resourceful, tough programmer, you drop the source code on your Xcode project, alongside the rest of your code. You build your project and get like 148 errors and 57 warnings. Naturally, there are lots of definitions that ./configure should have defined, and the source defaults must be those of a PDP-11, or something. You try to tweak the settings manually for 10 minutes before you give up.

Your next step is to tell the configure script to cross-compile for a different platform. But you don't know exactly how to tell it your platform is like Mac OS X, only running on an arm chipset, what's the problem about that. After reading the scripts and template files and googling your way around, you use something like ./configure --host=arm-apple-darwin. This doesn't work, either, because configure insists on using your standard Mac OS X system libraries and headers instead of the ARM ones for the iPhone. You then try to tell configure to use the gcc compiler in your /Developer distribution, and this still doesn't work. Oh, well. You know what you need to do - investigate compilation options and library locations - but it's painful.

Wouldn't it be nice to have some notes on how to set up your environment to compile an Unix package from the command-line, but using Xcode's development libraries for the iPhone?

The Solution



If you have read the introduction above, you will have noticed that it is just a feeble attempt to disguise the fact that this article is only going to tell you how to configure your environment variables to compile a Unix library using Xcode's toolchain from the command line. That's it. It is admittedly not a very glamourous or innovative task; however, we still had to devote a few lenghty hours to set everything up properly, following the embarrassing steps outlined above, one after the other.

So, without further circumlocutions, let us show the damned variables. I'll dissect one of the build scripts I have actually used, accompanying the definitions with some comments or caveats.

The following two definitions point to the root of the command line developer tools and iPhone SDK. You may need to modify them to update the location in your own system, or if you are using a newer version of the SDK:


export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS2.0.sdk



Next, let's save the current build environment - we'll use it later to build the i386 version of the library which will run in the simulator.


# Save relevant environment
U_CC=$CC
U_CFLAGS=$CFLAGS
U_LD=$LD
U_LDFLAGS=$LDFLAGS
U_CPP=$CPP
U_CPPFLAGS=$CPPFLAGS



We'll now define the values we need to use to target the ARM architecture. Compilation flags in my case look something like this:


export CPPFLAGS="-I$SDKROOT/usr/lib/gcc/arm-apple-darwin9/4.0.1/include/ -I$SDKROOT/usr/include/"
export CFLAGS="$CPPFLAGS -arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT"
export CPP="/usr/bin/cpp $CPPFLAGS"



Linking flags are a bit more tricky. You need to ensure the output of the compilation process is a static library, and not a dynamic library or an executable file. Dynamic libraries can in fact be produced, but the iPhone sandbox will sadly refuse to load them at runtime - only dynamic libraries and frameworks in predefined system locations can be used. There's a mention about this limitation somewhere in the Development Agreement.

Even though you won't be using dynamic libraries in your project, some packages are configured in such a way that it is easier to let them compile the dylib then ignore it, rather than trying to convince them not to create the dynamic code. If you encounter such a case, you should configure your linker in a way similar to this:


# dynamic library location generated by the Unix package
LIBPATH=src/.libs/<libname>.dylib
LIBNAME=`basename $LIBPATH`

export LDFLAGS="-L$SDKROOT/usr/lib/ -Wl,-dylib_install_name,@executable_path/$LIBNAME"



This will create a valid dylib file that you will be able to use within Xcode; however, it won't run in the iPhone as described above.

Therefore, you will actually be interested in using the static library version, so we'll store its location:


# static library that will be generated
LIBPATH_static=src/.libs/<libname>.a
LIBNAME_static=`basename $LIBPATH_static`



Now we are ready to run the configure script and build the libraries.


./configure CC=$DEVROOT/usr/bin/arm-apple-darwin9-gcc-4.0.1 LD=$DEVROOT/usr/bin/ld --host=arm-apple-darwin
make



Depending on the package you are trying to compile, you might need to supply additional arguments to the configure script. Some packages, for example, will accept arguments indicating whether a static library or a dynamic one should be built. It is also frequent to disable features or modules you know you won't use in your project. You need to refer to your package documentation for fine tuning details.

After make finishes (hopefully without errors), we'll move away the generated libraries to a safe location:


mkdir -p lnsout
cp $LIBPATH_static lnsout/$LIBNAME_static.arm



We repeat now the same steps, but targetting the i386 architecture. This will allow us to build libraries compatible with our iPhone simulator environment.


make distclean

# Use default environment
export CC=$U_CC
export CFLAGS=$U_CFLAGS
export LD=$U_LD
export LDFLAGS=$U_LDFLAGS
export CPP=$U_CPP
export CPPFLAGS=$U_CPPFLAGS

# Overwrite LDFLAGS
# Dynamic linking, relative to executable_path
# Use otool -D to check the install name
export LDFLAGS="-Wl,-dylib_install_name,@executable_path/$LIBNAME"

# ToDo - error checking
./configure
make

# Save generated binaries
cp $LIBPATH_static lnsout/$LIBNAME_static.i386



After we have produced the i386 and arm versions of our library, we will create a fat Universal Binary enclosure containing both of them:


# Create fat lib
$DEVROOT/usr/bin/lipo -arch arm lnsout/$LIBNAME_static.arm -arch i386 lnsout/$LIBNAME_static.i386 -create -output lnsout/$LIBNAME_static



Finally, you can add the generated library and any necessary development header files to your project and build it. If everything went well, your application will be linked with the library and will run correctly in both the simulator and the device.

As explained above, this is mostly basic Unix tinkering, but it took us a while to get the right configuration. Maybe we were just rusty, so if you know a better way to achieve this, please do let us know!

Saturday, June 21, 2008

WWDC 2008

If I had to summarize this year's WWDC in one word, it would be "Awesome". A year ago, we went to WWDC with no clear goals. We attended a lot of sessions, and met a few people. Overall, it was a good experience, in which we gained a lot of technical knowledge.

This year, it was different. Our primary goal was not to spend all of our time in sessions. We wanted to make our visit business oriented, meeting people, and getting feedback about different aspects of our applications.


After 2 years of working with him, we finally met Louie Mantia, our graphic designer. Currently, he works mostly for our friends at Tapulous, but, fortunately, he still does some work for LateNiteSoft.

DSC01642.JPG


We also met Chuck Soper, Cabel Sasser, Daniel Jalkut, Mike Lee, Kenichi Yoshida, Steve Scott, Tristan O'Tierney, Colin Wheeler, Kevin Hoctor, and some others in the SF Mac Indie Soiree.

During the week, we met with many Apple employees, as well as other entrepreneurs, developers, designers and journalists. We participated in a few labs and different consultancy sessions. We were present at the parties and events, but overall we probably did not make it to more than 5-6 sessions each.

The overall result has been very good, and we are very satisfied. Within the next few weeks we hope to start showing you the outcome of our visit.

Wednesday, February 27, 2008

iPhone programming tips: image orientation

One of our main focus when we started to write Sketches was to leverage as much as possible the existing technologies already available in the iPhone. This is not a new idea: just as all Mac OS X apps cooperate with each other, we thought that integrating Sketches with the rest of apps in the system would make it a far more fun and pleasing app.

Given the complete lack of documentation or experience, trying to figure out how the APIs work and fit together with each other was no easy endeavor. However, we bravely set out to study the Cocoa iPhone APIs, armed with our previous knowledge of desktop Cocoa, and a lot of patience. Sometimes we thought the effort might be overkill, but being perfectionists at heart, we were uneasy to deliver something that we ourselves considered suboptimal. We are satisfied with many of the results we got, and people seem to appreciate them too. In fact, we've had several fellow coders ask us about details in our image handling code, or how we manage to send emails from Sketches without actually launching MobileMail.

One of the areas we are frequently asked about is the way we handle images shot from the camera or picked from the photo album, and how we detect their orientation. Instead of answering the questions privately, we thought it could be interesting for others to post them here. Maybe our explanations will become outdated next week after The Event - if so, that'd be great news for all :)

In the following paragraphs I'll try to describe some of the interesting "features" I found when guessing how to use the Camera and Photo Album APIs, with a special focus on detecting orientation. I may be utterly wrong in my interpretations, but so far they have been working reasonably well for Sketches :)

* Warning: technical burble ahead *

The first idea that comes to mind if you want to have the camera shoot pictures and use them in your app, is to use the cameraController:tookPicture:withPreview:jpegData:imageProperties callback invoked by the CameraController class. It looks promising, but after some experimentation, we found this approach was not as flexible as we required. Instead, we are using a different mechanism in Sketches. We subscribe to the CameraImageFullSizeImageReadyNotification event, which is sent just after a new photo has been taken. Early in our development we decided to subscribe to all notifications and log them in a file, a simple technique that was instrumental to learn about the existence of this particular notification. In our code, the method that receives the notification is similar to the following:

- (void) cameraImageFullSizeImageReadyNotificationObserver: (NSNotification *) notification
{
NSLog( @"cameraImageFullSizeImageReadyNotificationObserver" );
[cc stopPreview];
CameraImage * cameraImage = (CameraImage *) [notification object];
if ( cameraObserver && [cameraObserver respondsToSelector: @selector(imageWasSelected:)] )
{
[cameraObserver performSelector: @selector(imageWasSelected:) withObject: cameraImage];
}
}


The important piece of information here is that the "object" property of the notification contains an instance of the CameraImage class, which belongs to the PhotoLibrary API framework. In a moment we'll show how to deal with CameraImage instances.

For photos picked with the photo album browser, we use the PLUIController class. A line like

[[PLUIController sharedInstance] setDisplayingPhotoPicker: YES];

will trigger selection of a photo from the photo album. If you set a delegate object, the photo album will invoke your delegate's imageWasSelected method, indicating as a parameter the CameraImage instance that corresponds to the image selected. Note we are using the shared PLUIController instance and do not instantiate a copy ourselves - results are more difficult to achieve the other way around, because the constructor of the shared object actually knows how the instance has to be instantiated, while we have no idea about the properties we should set to make it work.

Therefore, for both types of photo selection (shooting with the camera or selecting a photo from the photo album), we end up with a CameraImage instance to deal with. A CGImage can be created from the CameraImage, using the following API call:

int orientation;
struct CGImage * cgimage = [image createFullScreenCGImageRef: &orientation];

Now we have a Core Graphics image, which is a good thing because there's actually a whole lot of documentation about that.

However, this is where things get a bit hairy regarding how to determine image orientation.

First of all, there are three different sets of values that refer to orientation characteristics:

- If you copy photos from your iPhone to your computer and look at them in an EXIF browser, you'll see that they contain one of the following values: "1" for "normal" images; "3" for images that are rotated 180 degrees; "6" for images that are rotated 90 degrees; and "8" for images that are rotated 90 degrees counter-clockwise.
- The orientation value returned in the integer above does not correspond to the EXIF values just mentioned. The values returned by createFullScreenCGImageRef are, respectively: "1", "2", "3", "4". To make things amusing, images shot with your phone in the vertical upright position will typically be stored to disk with a 90 degrees CCW rotation; therefore, the orientation value you'll receive if you pick such a photo from the photo album will be "4".
- Third, the device orientation, as reported by UIHardware, uses a different set of values. They are the following: "1" (phone vertical, upright position); "2" (phone upside down); "3" (phone rotated 90 degrees CCW with respect to the vertical position); "4" (phone rotated 90 degrees CW).

Therefore, after you select a photo from the photo library, you should check the orientation value you get when creating the CGImage reference, and then you have to correct the rotation using the rotation and translation transformations provided by the CoreGraphics API.

For photos shot with the camera, however, the orientation value returned by createFullScreenCGImageRef at that particular callback is always "4", no matter what the device orientation is, or the way the photo is stored in the disk. This probably happens because my initialization of the camera related APIs is possibly incomplete, but I haven't figured out how to achieve a better result. For shots, therefore, what we do is use the device orientation value, then rotate the photos according to the description above.

Another option I tried was to open the physical files that refer to the CameraImage and read their properties. I was hoping to get the EXIF orientation value, but it seems that at this stage not many properties are available. In fact, code like the following yields a dictionary with just a "FileSize" property:

NSString * imgPath = [[image fileGroup] pathForFullSizeImage];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL( (CFURLRef) [NSURL fileURLWithPath: imgPath], NULL );
NSDictionary * imageProps = (NSDictionary *) CGImageSourceCopyProperties( imageSource, NULL );


We are using these techniques in the current version of Sketches, and will also be the basis for some new features we are still cooking up. We hope they are useful to other iPhone programmers too!