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

Disable Android 2.3 View overscrolling on prior versions

Android Gingerbread enables by default overscrolling in default orange style, which could be disturbing in many layouts.
To disable it you can use the setOverScrollMode method with the OVER_SCROLL_NEVER parameter, however it is not available on prior Android versions.
Here is a safe solution for all Android versions:

public static void disableOverscroll(View view) {
Class viewCls = view.getClass();
try {
Method m = viewCls.getMethod("setOverScrollMode",
new Class[] { int.class });
int OVER_SCROLL_NEVER = (Integer) viewCls.getField(
"OVER_SCROLL_NEVER").get(view);
m.invoke(view, OVER_SCROLL_NEVER);
} catch (Exception e) {
// swallow
}
}

By alex on Stackoverflow.com

EmailShare

Display only mail apps when calling ACTION_SEND intent

Maybe you have already noticed, that if you invoke the mail sender intent on Android, it may display a lot of installed apps, which can handle text/plain MIME-types, that may confuse the user.
To display only mail-capable apps, use message/rfc822 as the parameter of setType method.

Via 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

Android 3.x Action Bar customization

The ActionBar UI component has been introduced in Android 3.0 and above, and it seems to become the standard way to use tabs and context/action menus in Android applications.
You may also customize the ActionBar associated to your application in different ways through this great tutorial, however you might run into errors when you wish to override Tab item styles, to resolve this issue,
check this blog for a very straightforward solution. (due to private API issues)

EmailShare

Quicklook plugin for iOS provision files

Must have for iOS developers :)

EmailShare

Calculating angle between two GPS positions

Easy way to determine bearing/angle between two locations:
Source: Stackoverflow.com

----- CLLocation+Bearing.h

#import
#import

@interface CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation;
-(NSString *) compassOrdinalToLocation:(CLLocation *) nwEndPoint;

@end
---------CLLocation+Bearing.m

#import "CLLocation+Bearing.h"

double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};

@implementation CLLocation (Bearing)

-(double) bearingToLocation:(CLLocation *) destinationLocation {

double lat1 = DegreesToRadians(self.coordinate.latitude);
double lon1 = DegreesToRadians(self.coordinate.longitude);

double lat2 = DegreesToRadians(destinationLocation.coordinate.latitude);
double lon2 = DegreesToRadians(destinationLocation.coordinate.longitude);

double dLon = lon2 - lon1;

double y = sin(dLon) * cos(lat2);
double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
double radiansBearing = atan2(y, x);

return RadiansToDegrees(radiansBearing);
}

EmailShare

Android push messaging – C2DM

From Android 2.2 and above, push messaging is supported like on Apple iPhone through the C2DM service. The official developer site and blog features a good client example, but this article features a complete guide with server side PHP examples as well.

EmailShare