[ios] Now you can share bookmarks using Gmail.app

if you did no set up Mail.app
This commit is contained in:
Igor Khmurets 2013-12-05 21:15:59 +03:00 committed by Alex Zolotarev
parent 872b727545
commit 813c79501e

View file

@ -11,9 +11,10 @@
+(void)showShareActionSheetInView:(id)view withObject:(id)del
{
UIActionSheet * as = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"share", nil) delegate:del cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
if ([MessageComposeViewController canSendText])
[as addButtonWithTitle:NSLocalizedString(@"message", nil)];
if ([MailComposeViewController canSendMail])
if ([MailComposeViewController canSendMail] || [self canUseGmailApp])
[as addButtonWithTitle:NSLocalizedString(@"email", nil)];
[as addButtonWithTitle:NSLocalizedString(@"copy_link", nil)];
[as addButtonWithTitle:NSLocalizedString(@"cancel", nil)];
@ -22,6 +23,12 @@
[as release];
}
+ (BOOL)canUseGmailApp
{
// This is not official google api
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlegmail://"]];
}
+(void)resolveActionSheetChoice:(UIActionSheet *)as buttonIndex:(NSInteger)buttonIndex text:(NSString *)text
view:(id)view delegate:(id)del gX:(double)gX gY:(double)gY
andMyPosition:(BOOL)myPos
@ -45,23 +52,39 @@
+(void)sendEmailWith:(NSString *)textFieldText andUrl:(NSString *)shortUrl view:(id)view delegate:(id)del gX:(double)gX gY:(double)gY myPosition:(BOOL)myPos
{
MailComposeViewController * mailVC = [[[MailComposeViewController alloc] init] autorelease];
NSString * subject;
NSString * body;
NSString * httpGe0Url = [shortUrl stringByReplacingCharactersInRange:NSMakeRange(0, 6) withString:@"http://ge0.me/"];
if (myPos)
{
search::AddressInfo info;
GetFramework().GetAddressInfoForGlobalPoint(m2::PointD(gX, gY), info);
NSString * nameAndAddress = [NSString stringWithUTF8String:info.FormatNameAndAddress().c_str()];
[mailVC setMessageBody:[NSString stringWithFormat:NSLocalizedString(@"my_position_share_email", nil), nameAndAddress, shortUrl, httpGe0Url] isHTML:NO];
[mailVC setSubject:NSLocalizedString(@"my_position_share_email_subject", nil)];
body = [NSString stringWithFormat:NSLocalizedString(@"my_position_share_email", nil), nameAndAddress, shortUrl, httpGe0Url];
subject = NSLocalizedString(@"my_position_share_email_subject", nil);
}
else
{
[mailVC setMessageBody:[NSString stringWithFormat:NSLocalizedString(@"bookmark_share_email", nil), textFieldText, shortUrl, httpGe0Url] isHTML:NO];
[mailVC setSubject:NSLocalizedString(@"bookmark_share_email_subject", nil)];
body = [NSString stringWithFormat:NSLocalizedString(@"bookmark_share_email", nil), textFieldText, shortUrl, httpGe0Url];
subject = NSLocalizedString(@"bookmark_share_email_subject", nil);
}
if ([MailComposeViewController canSendMail])
{
MailComposeViewController * mailVC = [[[MailComposeViewController alloc] init] autorelease];
[mailVC setMessageBody:body isHTML:NO];
[mailVC setSubject:subject];
mailVC.mailComposeDelegate = del;
[view presentModalViewController:mailVC animated:YES];
}
else if ([self canUseGmailApp])
{
subject = [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
body = [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"googlegmail:///co?subject=%@&body=%@", subject, body];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}
mailVC.mailComposeDelegate = del;
[view presentModalViewController:mailVC animated:YES];
}
+(void)sendMessageWithUrl:(NSString *)shortUrl view:(id)view delegate:(id)del myPosition:(BOOL)myPos