jump to navigation

More than eye candy 19 February 2013

Posted by Oliver Mason in Apple, iphone, objective-c.
add a comment

For an undergraduate module in Digital Humanities I am currently coding an iOS app designed by our students (see @iBrumApp for the related twitter feed). This is a tourist attraction app about Birmingham. The students collect data on a number of interesting locations (images, descriptions, coordinates, …) and encode them in XML ready to put into the app.

In the app so far there is a map screen, which shows the locations of the attractions. This can be swapped for a list view, which shows the attractions as a table in text form, possibly with a short description and a category label. A segmented control allows switching between the two views.

Under the hood there are two views on top of each other, with one of them hidden. Pressing the segmented control unhides the hidden one and hides the previously visible one; that works fine. There is a simple method in the view controller which swaps the two views:

                 out:(UIView*)toHide {

    [toHide setHidden:YES];
    [toShow setHidden:NO];

However, it feels a bit sudden and ‘in your face’, the way the views are changing.

So, it might be better to soften the transition somewhat, for example with a cross-fade animation. Basically the visible view would become increasingly transparent, while the hidden view becomes increasingly opaque, until the old one is completely invisible. This is very easy to do with CoreAnimation:

                 out:(UIView*)toHide {

    [toHide setAlpha:1.0];
    [toShow setAlpha:0.0];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationCurve:
    [toHide setAlpha:0.0];
    [toShow setAlpha:1.0];
    [UIView commitAnimations];

[Note: there is probably a more elegant way using the new block syntax of Objective-C, but this works just fine].

This fading animation has indeed the desired effect, making the transition much smoother and less sudden; I feel this is an improvement in the feel of the app. It’s only a small thing, but if there is one thing you pick up as a developer in the Apple ‘eco-system’ it’s that small things matter. Attention to detail is important.

One thing I have not yet explored (as I’m only testing it with a small sample data set of two locations) is the performance: I have the suspicion that having two superimposed views with transparency might slow down the whole thing, as the iPhone tries to render the other view despite it being transparent. But in that case I can just add a line that sets the ‘hidden’ property to disable the view completely should that prove to be an issue.


On Planning and Reality 3 June 2010

Posted by Oliver Mason in Apple, iphone, objective-c, programming.
add a comment

When I got my iPhone a little more than a year ago, and started developing programs for it, I had a clear idea what my first program was going to be. However, as always, things turn out quite different from how you think they are going to be…

First, it did take me a bit to get used to Objective-C. Not because it is very different from Java (I used to program in C after all before Java came along), but because all the classes in the Cocoa framework need to be learned. There are subtle differences between those and their Java cousins, and after a bit more experience I believe that the Cocoa classes are actually more powerful and easier to use than their Java counterparts.

Some teething troubles, lack of automatic memory management on the iPhone, and a surfeit of squa brackets meant further delays. Finally I had a program written, but it needed more work on the graphics side, artwork and so on. The stuff that really makes a difference, but is very time-consuming and hard if you’re not used to using graphics software. So the easier way out was to write a different program, which is lighter on the artwork.

This then was a todo-list program, which is also suitable for planning small projects. I wanted a program like that, but didn’t want to fork out the money for Things, which also looked a bit like overkill. On the life hack blog I read an article by Dustin Wax on his moleskine setup, and that seemed like something usable, which I then went about implementing as an iPhone app. With a bit of help from a friend with the icon design, and thanks to freely available sound files and icons, ePlanner was born.

In ePlanner I tried out Core Data, which is really a lot easier than messing about with SQLite directly. It uses both tabs and navigation views, and a lot of tables. I found it rather tedious in that all the classes were almost identical, but only almost, not 100%, and it’s hard to see how that could be changed. The behaviour of those classes is ever so slightly different.

The submission procedure was very easy, thanks to a description I found on the web. My app did get rejected, due to a crash on a 3GS; but I don’t have a 3GS, so I could only test it on a 3G and an iPod touch. Thanks to Instruments I could track down the error, which was of course a memory management issue, but one without consequences on the machines I could test it on. After that was changed, the app went through, and has indeed been bought by people all over the world.

It is really a nice feeling to think that someone in Argentina is using my app, as is someone in Hong Kong, some people in the US, Sweden, etc. I used some free Google advertising at the beginning, but that is really expensive, though when I stopped it, sales began to trail off. But that could also have been an effect of it slipping out of the ‘newly released’ slots.

It is indeed not too hard coming up with a program that does sell. The overall process is not too hard, though there were some frustrating moments battling with the various code signing and certificate issues that Apple requires.

I since have bought an iPad, and am thinking of porting ePlanner to this; however, I’ll give it a while so that I get used to how the iPad works. Knowing your way round the platform makes it a lot easier to develop good software, and I am not yet sure how the UI design for the small iPhone screen can best be translated to the iPad’s larger display. But it will come, and I will describe the process on this blog…!

In the meantime, I will re-visit some of my previous program ideas, as it is really not hard to turn them into something that will end up in the App Store, and it is really satisfying to do so.

Single user vs Multi user: how will the iPad work? 17 March 2010

Posted by Oliver Mason in Apple, iPad, iphone.
1 comment so far

Note: this post is somewhat speculative, as I obviously do not have an iPad (yet!). It is simply an observation that got me thinking about how it is going to be used, and how that possible usage will influence the user experience.

I suspect that in our house the iPad will be a multi-user gadget.

I have an iPhone, my wife has got an iPod touch, and the kids currently use a clapped-out ancient Sony Vaio laptop whose disk is about to fail. Everybody has their own device to do things on. However, this is likely going to change when we acquire an iPad. I envisage this as being a general device that just lies on the sitting room table, to be picked up by whoever wants to use it for reading their email, checking something on Wikipedia, playing a quick game, adding an entry to a calendar, looking up a phone number, and so on.

When I check mail on my iPhone, it is set up to look at my email accounts. Similarly, the calendar is sync’d with my general calendar, and the address book is too. I don’t (and cannot) easily switch between identities (though it is possible to do so with mail and calendar). Some games that I play on my iPhone store their state in case of interruption, and I can resume them later. The same applies to other applications, which usually have one set of data they work with.

This is OK for a phone. Typically you have a phone, and you’re the only one using it, otherwise it’d lose some of its usefulness if you don’t know who you will reach when calling a particular number. But if the iPad is shared between people, how can I avoid reading my wife’s email, or swamping her address book with all my student email addresses (which Google puts into it automatically)? If I play a game, and then have to stop and go back to it later, what if one of my daughters wants to have a go in-between? She might not only end the game I’m playing, but also mess up my high-score records. My todo-list application only has one set of todos, so what if I look at it and suddenly find “Feed my puffle on Club Penguin” on top of my priorities?

On a Unix system you have different user accounts, and you log in and out; this avoids the problem on Mac OS X. But logging in and out is tricky if a system is shared. If I forget to log out when I interrupt my task, and the device is locked, nobody else can use it until I have come back. And how can this be made easy, without constantly having to remember a user name and password?

I somehow suspect that this will be an issue for which there is no satisfactory solution. But if the iPad is to become a general household item like a television or a radio, then there needs to be some non-intrusive way that allows easy sharing. I’m looking forward to finding out what Apple came up with here…!

What’s a UITextEffectsWindow? And why is it receiving messages? 17 September 2009

Posted by Oliver Mason in Apple, iphone, objective-c, programming.
1 comment so far

I just spent several hours (or at least it felt like several hours!) in frustration, searching a trivial bug. I’ve been testing a quick’n’easy prototype screen with an UIImageView and four UIButtons. The buttons are linked via an action to a view controller. And every time I press a button, my app conks out complaining that -[UITextEffectsWindow buttonPressed:] was an unrecognised selector. I checked the memory address, and it said it was my view controller, just before that exception was thrown.

I was ready to put the blame on some mistakes with Interface Builder, until I came across the solution (indirectly) in a blog: here the problem described related to properties, and the difference between vc = … and self.vc = …. I had another look at my code and quickly found the offending line: I had the view controller as a local variable in the app delegate’s ‘viewDidLoad’ method, and I autoreleased it. In other words, by the time the button was pressed the view controller no longer existed, and hence I got that weird error message.

This was not helped by the fact that ‘UITextEffectsWindow’ is not mentioned in the documentation anywhere, as it seems to be an internal UIKit class, but at least it appears to be consistent.

So, if your button presses send messages to ‘UITextEffectsWindow’, make sure to check that your view controller is still alive!

Application Promiscuity 7 September 2009

Posted by Oliver Mason in Apple, iphone, objective-c.
1 comment so far

I was getting a bit bored with the slow progress on my Esperanto dictionary app, and over the holidays I started work on a few other ideas I had. One was a Maths-drill program for kids, as the ones that are already out there (at least the ones I tried) don’t seem to be ideal (nothing ever is ideal, though!). So I tried writing another app so our kids could play and practice their maths skills.

That app is almost done, just the artwork and sound effects are missing. At the moment it looks pretty rubbish (but looks aren’t that important as long as it works and doesn’t crash!), and the sound effects are nicked from somewhere, so I have to replace them with free ones. Again, the purpose was to try things out.

That app was quite fun, and also easy to do. More on that later…

The next app is one that supports teaching and learning students’ names. This makes use of a navigation controller, which is slow going. I’m picking up loads of experience in Objective-C quirks along the way. For example: avoid using NSNumbers as the keys in a dictionary if you want to save it using writeToFile later on…

Overall it’s very exciting, and the iPhone is a fun platform. It’s really great to see your own stuff amongst all those polished apps, and provides great motivation to do better.

Making Progress! 26 June 2009

Posted by Oliver Mason in Apple, iphone, objective-c, programming.
1 comment so far

DAY 11 and the pace is picking up. I managed to sort out two of the four tabs of the app, one including a table display of Esperanto/English dictionary entries (with the proper Esperanto diacritics), and the other one being a live-search on the English gloss entries. This one even pops up an automatic keyboard when first selected; the tab bar controller sends it a message when it has been activated. I even managed to answer a question on stackoverflow.com on that issue.

I also found somewhere a hint on how to automatically shrink the label size if the text is too long, wrote a converter from the Esperanto x-notation to unicode, etc. Really pleased! Both of these will appear here later.

One thing I don’t like too much is writing all the UITableViewDelegate methods when using a table. Quite a lot of boiler-plate code, but then, it is quite powerful. I just couldn’t be bothered writing yet another set of those methods for the final tab, the info view part. But there is nothing technically difficult with it. Objective-C is also getting easier and easier, and the auto-completion feature and API doc integration of XCode really helps. Though I think for serious code I will still use vile…

That leaves pretty much only the core part of the app: the Esperanto morphological analyser. I will implement this as a finite state machine, and working with Cocoa has given me the idea to implement it using delegates; an abstract hull which calls methods on the delegates whenever it needs to retrieve data, or match something. I have the feeling that this is pretty similar to Erlang’s OTP frameworks.

It is a really rewarding experience to see your own app on the iPhone. If only I was better at designing the tab bar icons! And I can already foresee one objection: one of the tabs has a star icon, the star being the Esperanto symbol. I think I need to change that, as the star is reserved for the ‘favourites’ meaning, and I don’t think Apple would appreciate the use of a star (even if it looks slightly slimmer) with another meaning.

More problems solved 24 June 2009

Posted by Oliver Mason in Apple, iphone.
1 comment so far

DAY 10, second part. I was really annoyed by those database errors, and built in assertions to check for the size of the file, and whether the file existed at all. I think sqlite creates a database if the file doesn’t exist, and on subsequent runs the database is then empty and failure happens.

Then I had the nice situation where the program worked in the simulator, but not on the device (I wanted to check the speed on the actual phone). Again, first the file doesn’t exist, and then it’s empty. XCode didn’t seem to copy the file over. Finally it dawned on me, as I was searching for mentions of problems with copying files into the documents folder: my database file was not in the documents folder, it was within the application bundle. I thought about copying it over when the app first starts, but then, why bother? It’s a read-only database, so all I needed to do was to change the path in the db init code, using the application bundle instead of the documents folder, and hey presto, success!

I guess the problem was that I looked at the sample code for db stuff in the iPhone development book. Here a database is created in the documents folder, and I assumed that would be where my db should reside. Confusing, but finally sorted. Now I can go to sleep in peace!

Every character is important 23 June 2009

Posted by Oliver Mason in Apple, iphone, objective-c, programming.
1 comment so far

DAY 10, and a little bit of progress. I found one error, which was about to drive me mad, until I more or less by accident stumbled over the solution on stackoverflow.com; in answering a slightly different question, Rob Napier commented on a bug in the way NSLog() was used.
NSLog(@"Returning %@ rows", [nodes count]);
Here, the -count method returns an int, but the %@ symbol expects an object. Result: a bus error. You need to use %d instead. And here was I, thinking how great it is not to bother with the old printf format codes, using the %@ way instead. I hate the primitive type/object distinction!

I then also found that I had created two superimposed Table Views (did I mention that I don’t really like Interface Builder after all?), so that my table got overwritten and looked all wrong. Now I’m struggling with getting the table to start at the first entry, not the 35th (indexPath seems to start counting sections at 1, rather than 0), and all of a sudden my database won’t work.

Preparing a straightforward SQL statement suddenly fails. I did not change that part of the code, the database file is still the same as it used to be before the error occurred, and I did tell XCode to do a full clean. Still, the error remains.


Tab Bar Errors 22 June 2009

Posted by Oliver Mason in Apple, iphone, objective-c, programming.
add a comment

DAY 9 and more frustration. My ViewControllers didn’t seem to be called, and NSLog messages I put in didn’t appear on the console. And the whole thing crashed without me knowing what was going on.

Having another look at my iPhone development book, I realised the first mistake: the TabBar Controller wasn’t aware of which controllers to call up for the various tabs, something you need to set up in Interface Builder. Still don’t really like that way of doing things, as the fact you’ve done it (or not, as the case may be!) is not easily transparent.

After completing the tab bar attributes, the log messages suddenly turned up, which was good, and it also doesn’t crash. Well, at least not where it used to crash. Now it crashes in the loop where I read stuff out of the SQLITE database, and it crashes after the second iteration. Wonder what the cause is. Probably memory management. Mixing Objective-C and plain C makes things a bit confusing. And I don’t like that NSString is an object you need to allocate, but NSInteger is basically just an alias for int, so a primitive data type rather than an object.

Anyway, more bug hunting coming up. It all feels terribly slow, but then I’m only spending a few hours every couple of weeks on it at the moment.

App Store Idiots 20 June 2009

Posted by Oliver Mason in Apple, iphone.
Tags: ,
1 comment so far

You have to be very careful when looking at reviews and ratings in the iPhone App Store (does ‘App Store’ need the ‘iPhone’ qualifier?). Some reviews are good and point out genuinely positive or negative issues with apps, but the majority can safely be ignored, as shown by the uselessness of their comments (‘this app is rubbish, I want my money back’) and their inability to match what they say with what they do. The number of times I have seen reviews where the reviewer wrote ‘This app gets 5 stars from me!’ when they actually gave ONE, or the reverse (‘this cr*p app gets zero stars from me’, but giving 5) is astonishing. Either those people are innumerate or incapable of keeping more than one thought in their head.

I haven’t got any hard facts, but have read somewhere that people are paid for leaving positive reviews of some apps and negative reviews of competing ones. That is about the only explanation for the number of stupid reviews that isn’t too depressing.