Wednesday, November 28, 2012

Cocos2D and applicationWillEnterForeground


When waking up i.e. relaunching an app (either through springboard, app switching or URL)applicationWillEnterForeground: is called. It is only executed once when the app becomes ready for use, after being put into the background, while applicationDidBecomeActive: may be called multiple times after launch. This makes applicationWillEnterForeground: ideal for setup that needs to occur just once after relaunch.
applicationWillEnterForeground: is called:
  • when app is relaunched
  • before applicationDidBecomeActive:
applicationDidBecomeActive: is called:
  • when app is first launched after application:didFinishLaunchingWithOptions:
  • after applicationWillEnterForeground: if there's no URL to handle.
  • after application:handleOpenURL: is called.
  • after applicationWillResignActive: if user ignores interruption like a phone call or SMS.
applicationWillResignActive: is called:
  • when there is an interruption like a phone call.
    • if user takes call applicationDidEnterBackground: is called.
    • if user ignores call applicationDidBecomeActive: is called.
  • when the home button is pressed or user switches apps.
  • docs say you should
    • pause ongoing tasks
    • disable timers
    • pause a game
    • reduce OpenGL frame rates
applicationDidEnterBackground: is called:
  • after applicationWillResignActive:
  • docs say you should:
    • release shared resources
    • save user data
    • invalidate timers
    • save app state so you can restore it if app is terminated.
    • disable UI updates
  • you have 5 seconds to do what you need to and return the method
    • if you dont return within ~5 seconds the app is terminated.
    • you can ask for more time with beginBackgroundTaskWithExpirationHandler:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
 [[CCDirector sharedDirector] resume];
 [[CCDirector sharedDirector] startAnimation];
}

- (void) applicationDidEnterBackground:(UIApplication *)application
{
 [[CCDirector sharedDirector] stopAnimation];
 [[CCDirector sharedDirector] pause];
}

- (void)applicationWillResignActive:(UIApplication *)application {
 [[CCDirector sharedDirector] stopAnimation];
 [[CCDirector sharedDirector] pause];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
 [[CCDirector sharedDirector] stopAnimation]; // Avoid 2 Display Link Crash ***
 [[CCDirector sharedDirector] resume];
 [[CCDirector sharedDirector] startAnimation];
}


Sources:

Saturday, November 24, 2012

Friday, November 23, 2012

Objective-C Categories to Extend Collections

My first use for Objective-C categories was to extend the NSArray class to act like a Stack and then later, like a Queue.

Here is a post about how to use categories:
http://macdevelopertips.com/objective-c/objective-c-categories.html

Here is a post about how to use them to make Stacks and Queues:
http://stackoverflow.com/questions/817469/how-do-i-make-and-use-a-queue-in-objective-c

One thing that initially threw me for a loop is the naming. They do expect you to use a '+' in the name and that is OK in Mac OS X and XCode.

Another thing that threw me for a loop is that unlike a Generic or a sub-class, they're simply injected (available) for every instance of the object to whom the category belongs.

That is to say, you do not need to create a Stack -- if you have the category, all your NSArray can now act like a Stack if you send that message to the instance.


1024x1024 Icons Look Funny (Gloss) in iTunes Connect

Do not be alarmed, my friend, your icon will always look funny after you upload it into iTunes Connect.

Our loyal partners over at Apple App Store will make some adjustments to your icon during the application submission process and it appears that everything just works out in the end if you don't worry and learn to love the App Submission Process.

http://stackoverflow.com/questions/8804236/ios-app-icon-has-glossy-effect-on-app-store-and-itunes-connect

Bundle Version and Bundle Build in XCode 4

The SO question that helped me most yesterday was:

http://stackoverflow.com/questions/7281085/whats-the-difference-between-version-number-in-itunes-connect-bundle-versio


Apple has a lot of information too, of course:



They all refer to the version of your application.
  • iTunes Connect
    This is the version number shown in the App Store; This must be a pure version number like1.2.3
  • Bundle Version (CFBundleVersion)
    This doesn't need to be a pure version number. This can be something like 12345 or 1.2.3 (Build 12345AB). This is shown in the About window for Mac OS X apps for example and is often more a "Build Number" than a "Version Number".
  • Bundle Version String (CFBundleShortVersionString) This value is used as the "real" version number. This must be the same string as used for the version in iTunes Connect.



Thursday, November 22, 2012

iPhone and iPad Debugging for Star Traders RPG

I was working on device compatibility between various iPhone devices and was having trouble clearing out a particular configuration so I could test. I was using the iPhone Simulator and was just about to pull out my hair until I found this simple solution:


I was having this weird MP3 playing error on my iPod that was inconsistent and eventually just stopped appearing:

The error was "The operation couldn’t be completed. (OSStatus error -50.)"


I found out if you pop a modal dialog over an OpenGL view in Cocos2d without saying YES to animated you will get crazy errors:

The error was "OpenGL error 0x0506 in -[EAGLView swapBuffers]" and the screen just wouldn't update correctly
http://www.cocos2d-iphone.org/forum/topic/20318


I also found some issues with different iPhone devices related to the Cocos2d "Animation Started" property and had to work around some odd issues with the Cocos2d template project...

The error message was "displayLink must be nil. Calling startAnimation twice?"
http://www.cocos2d-iphone.org/forum/topic/7326