programming
Behavior changed for parentViewController in iOS 5
Previously, if we present a modal view controller using:
[self presentModalViewController:modalViewController animated: YES]
We should able to get back the parent of the modal view controller using:
[modelViewController parentViewController]
and normally we will dismiss the view controller using:
[[modelViewController parentViewController] dismissModalViewControllerAnimated:YES];
Set the Company Name in XCode 4
In XCode 3.x, we have to set the following company marco so that new source code won't show __MyCompanyName__ in new source code:
defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ "ORGANIZATIONNAME" = "First Water Tech Ltd"; }'
However, it won't work in XCode 4. According to XCode 4 release note:
Convert between NSData and NSDictionary
We can simplu use NSKeyedArchiver to serialize NSDictionary. To convert NSDictionary to NSData:
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:yourDictionary forKey:@"Some Key Value"];
[archiver finishEncoding];
[archiver release];
/** data is ready now, and can use it **/
[data release];
To deserialize a NSData:
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]];
Streaming video on android
Playing streaming MP4 video from a URL is a piece of cake in iPhone, but not the case in android. Firstly you have to create your own activity to play video using MediaPlayer class. It is not difficult because there is sample code in the APIDemo projects in the SDK. However, after success to play it on my Nexus One with OS 2.2, I found that it won't play on my G1 with OS 1.6, with error "sorry,this video is not valid for streaming to this Device.."
Manually set the locale of an application in iPhone
The following code will change the locale of the application to Chinese. However, you must set it in the beginning of the app, and it will take effect in next launch of the app.
[[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObject:@"zh"] forKey:@"AppleLanguages"];
Manually set the locale of the application in Android
Android provides a flexible support of localization that system will load different resources according the locale of the current system configuration. However, sometimes we want to manually change the locale of our application especially for our Hong Kong market that people may want to have Chinese locale application in a English system configuration.
To do this, we can set the configuration of the application using the following code:
Header:
import android.content.res.Resources;
import java.util.Locale;
Pull down to refresh table view
An easy way to add twitter like pull down to refresh function to any table view. No dependency to other libraries, only include the 4 source files and 1 resource file to use it.
How does it work?
UIGraphicsBeginImageContext and retina display
To support retina display, you need to set the scale of UIImage correctly. If you use UIGraphicsBeginImageContext to create offline image, you should use UIGraphicsBeginImageContextWithOptions instead to set the correct scale of the image. Below is the help function that will call with correct scale according to the scale of current device and will use the old function if the OS version of the device is below 4.0 that UIGraphicsBeginImageContextWithOptions is not available.
To use the code, simply replace all UIGraphicsBeginImageContext with RetinaAwareUIGraphicsBeginImageContext
Use UIGestureRecognizer to handle single tap and double tap
Below the code to use UITapGestureRecognizer to handle single tap and double tap. The code is designed that it won't fire single tap event if we got double tap event. The trick is use requireGestureRecognizerToFail to ask the single tap gesture wait for double tap event failed before it fire. So when the user tap on the screen, the single tap gesture recognizer will not fire the event until the double tap gesture recognizer. If the double tap gesture recognizer recognize the event, it will fire a double tab event and skip the single tap event, otherwise it will fire a single tap event.
How to compile ffmpeg for iPhone
- Download and install the iPhone SDK 3.1.
- Get the latest gas-preprocessor and install it in /usr/local/bin or some other directory in your $PATH.
http://github.com/yuvi/gas-preprocessor/ - Get the latest FFmpeg from SVN (minimum r20151).
- Configure FFmpeg with one of the following commands. These give a
clean build with a default installation of iPhone SDK 3.1 on OSX Leopard.
Other versions may vary. - For iPhone 3GS or iPod Touch 3G 32GB/64GB, use this command:

Recent comments
17 weeks 6 days ago
23 weeks 1 day ago
26 weeks 3 days ago
27 weeks 3 days ago
36 weeks 2 days ago
36 weeks 2 days ago
36 weeks 2 days ago
36 weeks 4 days ago
38 weeks 2 days ago
38 weeks 3 days ago