Parsing date fields with NSDateFormatter ignoring locale

In many cases if the iOS device international settings is not set to US, you may have errors parsing text-based dates from e.g. RSS feeds.
The solution is to set the NSDateFormatter locale to en_US_POSIX.

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatter setLocale:locale];
[locale release];

by Luke Redpath on Stackoverflow.com

EmailShare

Android Toast-like HUD for iOS

If you wish to easily report status of background processes to the user, on Android you may use Toast class, however iOS lacks of this great feature. But there is a great library, that provides even more features than Android version: MBProgressHUD.

EmailShare

Adding settings bundle to iOS app

If you want to add your app’s settings to the main iOS settings page, there are some pretty easy and straightforward steps to do it, which is presented very well in the following tutorial.

EmailShare

“Real” URL encoding in iOS

Sometimes if you wish to encode a whole URL including /,&,: , [NSString stringByAddingPercentEscapes:] fails, to solve this issue, use CFURLCreateStringByAddingPercentEscapes

+ (NSString*)urlEncode: (NSString*) url {
NSString* encoded = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)url, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
return [encoded autorelease];
}

Source

EmailShare

Quicklook plugin for iOS provision files

Must have for iOS developers :)

EmailShare

Error adding EKEvent on iOS 5

If you try to add an EKEvent with startDate equals to endDate to EKEventStore on iOS5, it will throw an error like “No end date has been set”.
To get rid of this problem, you should add a second to endDate property, something like:

if ([event.endDate isEqualToDate:event.startDate]) {
event.endDate = [event.startDate dateByAddingTimeInterval:1.0]; // add one second
}

Source: stack overflow

EmailShare

After upgrading ASIHttpRequest, responseStatusCode returns 0

If you are using ASIHttpRequest to download large files and cache them, you may run into an issue with request.responseStatusCode value is 0 after upgrading to version 1.8.1.
To fix the issue, check this github issue.
You should replace this line in the original source code:
[self setResponseStatusCode:[[headers objectForKey:@"X-ASIHTTPRequest-Response-Status-Code"] intValue]];

EmailShare

Play videos with MPMoviePlayerController in landscape-only

Today’s HD videos displayed best on 16:9 sized displays, which is available on iOS devices as well in landscape mode.
That’s why it is useful to start 16:9 videos in landscape mode, and even don’t allow to be rotated in portrait mode.
Here is a good tutorial about MPMoviePlayerController usage, with good example, however to start in landscape mode, apply the following lines in your ViewController, which owns the MoviePlayerController’s view:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;
}

EmailShare

Ignoring ringer mute switch for audio/video playback

If you wish to let your app playback audio independently from mute switch, check the following tutorial, including sample code.
The most important part of the code:

NSError *_error = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &_error];

import AVFoundation/AVFoundation.hu and also add the framework with the same name to linking build phase.

EmailShare

Drawing polyines or routes on a map view in iOS4

Drawing routes on MKMapView is dramatically simplified in iOS4. There are predefined helper classes, which make it much more easier than in iOS3. Although little C coding required, the whole process can be done in a few lines of code.
Here is a great tutorial with downloadable sample project: The Reluctant Blogger

EmailShare