Archive for June, 2010

22 JuniOS 4.0 released, what’s that?

It’s a very expected update.

There are so much new features and possibilities that I couldn’t decide what to taste first and decided to continue everyday work. Later watching forums comments I see that the first thing everyone wants to do is to update an app by supporting 4.0, but surely it have to run on previous version also, 3.0-3.1. The right way is to open project settings and set:

  • Base SDK – iPhone Device 4.0
  • iPhone OS Deployment Target – iPhone OS 3.0

After recompiling it’ll turn to background properly, but still work on 3.0+ versions.

The second thing is the multitasking, of course.

There are two new UIApplicationDelegate’s methods for that. One when application was turned in to the background by pressing Home Button and one when turned out by pressing an icon on the spring board. As an example of background in/out workaround I provide using of Google Analytics, which is actually needed to be stopped and started:

- (void)applicationDidEnterBackground:(UIApplication *)application{
[[GANTracker sharedTracker] stopTracker];} -
(void)applicationWillEnterForeground:(UIApplication *)application{
[[GANTracker sharedTracker] startTrackerWithAccountID:@”xx-xxxxxxxxxxx ;)
dispatchPeriod:20             delegate:nil]; [[GANTracker sharedTracker]
trackPageview:@”/” withError:nil];

// you could animate splash screen there}

If you’ve not read about what background is for then try this and this. It was discussed earlier the release.
Apple developer documentation for background execution.

The last I couldn’t get if it’s necessary to show splash screen when an app is coming back to foreground. It’s blinking for a moment each time :( Since having an animated Default.png I just copy animating piece of code to “applicationWillEnterForeground” and it’s become better. But it’s not a common solution. See what Apple says about the Default.png in HIG (updated 2010-06-03):

To enhance the user’s experience at application launch, you must provide at least one launch image. A launch image looks very similar to the first screen your application displays. iPhone OS displays this image instantly when the user starts your application. As soon as it’s ready for use, your application displays its first screen, replacing the launch placeholder image.

Supply a launch image to improve user experience; avoid using it as an opportunity to provide:

An “application entry experience,” such as a splash screen 

An About window 

Branding elements, unless they are a static part of your application’s first screen

Because users are likely to switch among applications frequently, you should make every effort to cut launch time to a minimum, and you should design a launch image that downplays the experience rather than drawing attention to it.

Design a launch image that is identical to the first screen of the application, except for: 

Text. The launch image is static, so any text you display in it will not be localized.

UI elements that might change. Avoid including elements that might look different when the application finishes launching, so that users don’t experience a flash between the launch image and the first application screen.

Obviously there is no suggested solution yet. The problem is about foregrounding app may appear from any view, it’s not first main view as it’s used to be. So it seems better to use some branded image as a splash screen instead part of a UI. Or don’t use splash at all. It could also be a solution if we can set to ignore a splash when app is launched from background. Anyway not a big deal.

Other 

The other things I mentioned at this time is the iOS simulator was updated. Now it has all three devices: iPad, iPhone, iPhone 4. The last has a camera simulator, but it does not work as you could suggest, it’s just a gap. iPhone simulators have “iAd tester” and “Game Center” for a sandbox. Pretty cool.

One more option is TV Out. It’ll be useful for our great apps presentations. It probably could help to record app demos with a better quality.

Have a nice learning.

Remember Apple provides free videos from WWDC 2010 this year. I’m sure everybody will find useful stuff for your self.

UPD:
I think we should remember a timedate of ‘applicationDidEnterBackground’ for better analytics tracking. And when ‘applicationWillEnterForeground’ try to decide if it’s clear run or run from background. I use 120 seconds time difference and two url names for tracking like that:

- (void) startGoogleAnalytics{ [[GANTracker sharedTracker]
 startTrackerWithAccountID:@"XX-xxxxxxx-xx"             
dispatchPeriod:20             delegate:nil];  if (lastBackground)
{  if ([[NSDate date] timeIntervalSinceDate:lastBackground] > 120)
[[GANTracker sharedTracker] trackPageview:@"/" withError:nil];
else   [[GANTracker sharedTracker] trackPageview:@"/foreground" withError:nil];
[lastBackground release], lastBackground = nil; } else  
[[GANTracker sharedTracker] trackPageview:@"/" withError:nil];}

19 JunFetch a random record with CoreData

-(NSArray*)getRandomRecords{  NSFetchRequest *request =
[[NSFetchRequest alloc] init]; NSEntityDescription *entity
= [NSEntityDescription entityForName:@"QuotesDB" inManagedObjectContext
:managedObjectContext];  [request setEntity:entity]; [request setFetchLimit:25];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@”viewCount” ascending:YES]; [request setSortDescriptors:
[NSArray arrayWithObjects:sortDescriptor, nil]]; [sortDescriptor release];
NSError *error = nil; NSArray *fetchResults = [managedObjectContext
executeFetchRequest:request error:&error]; [request release];
return fetchResults;} -(QuoteRecord *)getRandomQuote{ if (!randomRecords
|| randomRecords.count == 0) {  [randomRecords release];  randomRecords =
[[self getRandomRecords] mutableCopy]; }  QuoteRecord *q = [randomRecords
lastObject]; q.viewCount = [NSNumber numberWithInt:([q.viewCount intValue]
+ 1)]; [randomRecords removeLastObject]; return q;}

-(QuoteRecord *)getRandomQuote{  NSFetchRequest *request =
[[NSFetchRequest alloc] init]; NSEntityDescription *entity =
[NSEntityDescription entityForName:@"QuotesDB"
inManagedObjectContext:managedObjectContext];
[request setEntity:entity]; [request setFetchLimit:25];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:@”viewCount” ascending:YES]; [request setSortDescriptors:
[NSArray arrayWithObjects:sortDescriptor, nil]]; [sortDescriptor release];
NSError *error = nil; NSArray *fetchResults = [managedObjectContext
executeFetchRequest:request error:&error]; [request release];
int selectedItem = arc4random() % fetchResults.count; return
[fetchResults objectAtIndex:selectedItem];}
I worked with CoreData not much, so it’s always surprising with efficiency and velocity. Each small task seems to be a challenge. Not speaking about Python/Django with its very easy database APIs, that’s the last thing of non iOS stuff I totally liked to use. Today I want to share some snippets with fetching a random quote using iOS CoreData.

Take simple quote data structure. There are fields: ID, author, text and viewCount. To obtain a random record we need to:

  • get an entire quote number in DB
  • generate a random index of quote’s ID
  • fetch a record with that ID from DB
operation as random fetching costs to us:
  1. 130 milliseconds for ‘arc4random()’ one
  2. 300 milliseconds for viewCount approach
  3. 310 milliseconds one time for 25 random records and 0 for next 25 pages

13 JunHello, iOS developer generation

Additionaly to all other awesome features and updates we have a normal occupation name now. Our words have being heard and we have one predefined sufix instead of iPhone/iPodTouch/iPad/… . Now I think about new subdomain ios-dev-tips.alterplay.com as a synonym to the current.

My congrats, iOS developers!



To make a post more informative there are some news from WWDC 2010 I remember the most from the Keynote Video:

  • iPhone4 with a brandnew design and many other features. It has a gyroscope, that’s why it’s possible to make VERY accurate 3-axis space positioning. I’ve noticed it as a first, because historically my first crazy idea needed this piece of hardware. Two years ago I thought about the stuff like Wii can do now. That one was similar to real ping-pong. May be I’ll return to them somewhen.
  • iAds. There is a very many apps which is good enough to not use a AdMob like, but which can’t be paid because of some reasons, e.g. market specifics. Since I own one I want to test iAds ASAP with the Forismatic app. I’m sure it’s necessary to integrate it carefully and bit by bit.
  • iBooks for the iPhone. I wasn’t wait it, but it has a great design and MUST LEARN for all developers as a GUI solution. I’ve moked up several GUI ideas at the same time. Not sure it’ll inspire everybody, but worth to try.
  • 3 main refuse reasons: an app does not function as a developer describes, private APIs and an app simply crashes. It sounds sadly :(
  • 1500+ new APIs, it’s awesome number and gona be hard to update knowledge for free
  • 100 UI features, e.g. contact groups, app groups, wallpapers, FaceTime, fully black/white back/front of the iPhone4 and so on.
  • statistics, statistics, stat… (snoring)
Many things were expected and most of them look cool and/or perspectively. 
There is an youtube version of the keynote:

And a cut one for those who currently doesn’t have a free time: