Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 89

SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
12/17/15 09:43 PM (8 years ago)

Getting your iPad Email on...

So it seems that emailing a screen works fine on an iPhone, but for no reason (actually, I know the reason, but that's beside the point) it doesn't work on iPad. Here's how to remedy that. Summary: Send email from within the plugin, and don't hand it off to the BT Core. 1) Add 'MFMailComposeViewControllerDelegate' to your plugin '.h' file: @interface SW_somePlugin : BT_viewController <MFMailComposeViewControllerDelegate> If it already has a delegate, just add it, and separate them with a comma (,). In your plugin '.m' file, find this method: -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { and search for this line: [self sendEmailWithAttachmentFromScreenData:[self screenData] theAttachmentData:tmpAttachmentData attachmentName:[self saveAsFileName]]; comment it out, and add this code beneath it: Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if(mailClass != nil){ if([mailClass canSendMail]){ <yourAppName>_appDelegate *appDelegate = (<yourAppName>_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_navController *theNavController = [appDelegate getNavigationController]; MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker setToRecipients:nil]; NSData *attachmentData = [NSData dataWithContentsOfFile:[BT_fileManager getBundlePath:[self saveAsFileName]]]; [picker setSubject: [NSString stringWithFormat:@"Woot! %@", [appDelegate.rootApp.jsonVars objectForKey:@"name"]]]; [picker addAttachmentData:attachmentData mimeType:@"text/html" fileName:saveAsFileName]; [theNavController presentViewController:picker animated:YES completion:nil]; }//can send mail }else{ [self showAlert:@"Email Not Available" theMessage:@"Your device cannot send Email Messages" alertTag:01]; } and this will work for both iPad and iPhone. It's possible some of the variables (aka properties) need to be altered slightly to match your plugin. Hope this helps! Cheers! -- Smug
 
CMCOFFEE
Android Fan
Profile
Posts: 2017
Reg: Jan 04, 2013
Amarillo, Texas
26,670
like
12/21/15 06:27 PM (8 years ago)
awesome thanks!
 
Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
like
12/24/15 09:24 AM (8 years ago)
Smug you're THE BEST!!. Thanks so much for this solution it's just what I needed. I changed attachment type from text/html to pdf and works perfectly for locally stored files "packaged pdf's" but if the pdf's are being pulled from a url what code would I use by the attachment data line because currently it doesnt attach the file if its source is a url.
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
12/24/15 11:20 AM (8 years ago)
Well there are a couple of ways I'd approach it. It won't attach a URL, so you'd either have to: a) download the URL to cache first and 'then' attach it... b) forget attaching; add the URL in the message body, and let the user download it. "B" is the easier choice, all things being equal. you'd want to add and modify this code along with what is above: NSString *myMessageBody = @"http://www.myserver.com/link/to/file.pdf"; [picker setMessageBody:myMessageBody isHTML:YES]; If you're handling both local and URL pdf files, you may want to throw some kind of 'if local file, do this, if URL do that' kind of statement in there to attach local, or link the URL... Cheers! -- Smug
 
Sherry
Lost but trying
Profile
Posts: 135
Reg: Jan 05, 2013
South Africa
11,650
like
01/04/16 02:19 PM (8 years ago)
Hi Smug If I would like to use what you mention above as option a) download the URL to cache first and then attach it. What code would I use? Here is my senario - the user opens a pdf doc from a url link using pdf doc plugin, if its the first time they are opening the pdf, it automatically downloads to cache if its the 2nd time opening the pdf, the cached file displays on their screen. Now I need that specific cached file they are currently viewing to be attached in the email when they click on the send email button. The app contains around 60 pdf files so that is why I am wanting only the file they are currently viewing to be attached. Thanks Sherry
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.