Monday, June 24, 2013

Custom Framework for iOS

This entry is for my future reference.

In iOS & MacOSX development, a framework is basically a folder contains headers, nib files, images, object files and other files. Apple provides a list of frameworks along with iOS SDK. Unfortunately, Apple does not provide (or intentionally hided) the ability for Xcode to create custom iOS framework. Without custom framework, it will be troublesome to provide pre-built libraries with UI to external parties. Fortunately with some tricks/hacks one can create a static link custom framework. Please refer to following references.


Monday, April 22, 2013

Releasing AVPlayerLayer and AVPlayer

While using AVPlayerLayer and AVPlayer together, I found that the retainCount of the AVPlayer object is not decremented immediately upon destroying the associated AVPlayerLayer. It seems to be scheduled some time later. If I release them in applicationDidEnterBackground: the free-up progress will just stopped (and the app entered into background) before the freeing is completed. This caused some problems in my project. After some searching, I found that beginBackgroundTaskWithExpirationHandler: allows running background task and so it gives time for the non-finished free-up task. I simply adding it to applicationDidEnterBackground: and the free-up is done completely.
- (void)applicationDidEnterBackground:(UIApplication *)application
    UIBackgroundTaskIdentifier identifier = UIBackgroundTaskInvalid;
    identifier = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
        [[UIApplication sharedApplication] endBackgroundTask:identifier];

Update: After some searching and trying, I found that a better way is to listen to UIApplicationDidEnterBackgroundNotification event in my class, and I do not need to use the background task hack anymore then.
[[NSNotificationCenter defaultCenter] addObserver:self