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.
Display only mail apps when calling ACTION_SEND intent
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.
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.
“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
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);
}
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
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]];