UI web view attached to email - ios5

Im trying attach a UI webview to the email body in my project. I have a combination of text fields and ui webview. When I try to attach the UI WebView the text boxes ok appear but the the uiwebview contents do not.
NSString *emailBody = [NSString stringWithFormat:#"%#%#",textfieled.text,webview.tag];
[mail setMessageBody:emailBody isHTML:YES];
I realise the .tag might be incorrect on the webview, could someone tell me what i should be putting there (or doing wrong)as I have tried all combinations available?

Related

UIActivityView doesn't display other apps as option to open pdf

I'm displaying a PDF in my app and I want to have to same "openIn" functionality as the default iOS mail client.
The code I have is as follows:
NSURL *url = [NSURL fileURLWithPath:#"/var/mobile/Applications/21D850EA-409A-4231-BDFE-6B79FC721DA3/Library/Caches/1373665423163257247920130712/84cd7f88cf1b400cb1f4a4d6ac439649.pdf"];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[url] applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
I've hard coded the path for testing.
The first image below is how it looks in the mail client.
The second image is how it looks in my app.
Any help would be great.
You misunderstand what is happening. In the Mail app you have opened the PDF in the preview window. The actions icon then brings up a UIDocumentInteractionController with the standard "options" menu.
The UIActivityController does not provide any "open in" functionality. If your want the same options in your app as from the Mail attachment preview window, use a UIDocumentInteractionController and use one of the presentOptionsMenu... methods.

How to link the text field with my email in my app?

How can I send the information that the user inset in text field UITextField to my email?
and how can I let the information page shows once, only at the first time the user enters the app?
What you're asking is vague, but to take the data entered into a textfield and put it in a string just use:
NSString *theEmailBody = theTextField.text;
From there you can send an email using the standard Apple email framework:
MFMailComposeViewController *mail =[[MFMailComposeViewController alloc] init];
NSString *theEmailbody = theTextField.text;;
[mail setMessageBody:theEmailbody isHTML:NO];
or by making your own mail server and sending the HTTP request there.
You can use the following code in you function to send email.
MFMailComposeViewController *mail =[[MFMailComposeViewController alloc] init];
NSString *emailbody = textField.text;;
[mail setMessageBody:emailbody isHTML:NO];
Apple has sample code to show you how to set up in app email (linked below)
After you've done this, you can easily change (for example) the body of your email to be the contents of your textField by adding this where appropriate.
NSString *emailBody = myTextField.text;
Then additionally, if you wish for the information page to only be visible the first time the app is launched, look into NSUserDefaults. This will allow you to store and retrieve a value to let the app know wether or not to load your information page.
https://developer.apple.com/library/ios/#samplecode/MailComposer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008865

Attachments using email uri scheme in iOS

I am implementing an iphone application (iOS 4.2) from where I would like to trigger the email client to send messages with attachments. I could effectively use uri schemes in combination with the class NSURL in order to trigger the email app but I was wondering whether it is possible to attach images. I have tried with mailto:whoever#wherever.org?subject=sthg&body=sthgelse&attachment=/path/to/file but the attachments are not included. I know iphone applications are sandboxed therefore it is possible that the email utility were not able to access the path to my image since it is located in my application bundle. On the other hand I was considering to administer my images with the photo manager. (1) Is there a way to include attachments in this way? (2) If so, is it possible to reference images either from my app or from the photo client? I could not find any attachments argument in the mailto RFC but maybe Apple has provided some way to achieve this.
Thanks in advance for your help,
Luis
MFMailComposeViewController will be able to do that, some example of usage belows:
remember to add MessageUI.framework
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:#"Whatever"];
// Set up recipients
NSArray recipients = [NSArray arrayWithObject:#"whoever#wherever.org"];
[email setToRecipients:recipients];
// Attach an image to the email
UIImage *attachment = ...;
NSData *data = UIImagePNGRepresentation(attachment);
[email addAttachmentData:myData mimeType:#"image/png" fileName:#"ok.png"];
// Fill out the email body text
NSString *emailBody = #"test mail";
[email setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[email release];
Instead of using the mailto: URL scheme, you should use the MFMailComposeViewController which allows you to add attachments. It also has the added benefit that using will not leave your app.
If one does not have account MFMailComposeViewController simply crashes.
Yes, you can call canSendMail first with the result NO(!), what next?
The answer is - use 'mailto:'. It'll popup dialog to create account.

Add table view to the body of email in iPhone

I was working for a mail app using MFMailComposeViewController.
web page was loaded when user cliks on a button.
i set recipients sender, cc to the mail.
i attach one image to the body of email using follow code:
[mailpage setToRecipients:toRecipients];
[mailpage setCcRecipients:ccRecipients];
[mailpage setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:#"iCon" ofType:#"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[mailpage addAttachmentData:myData mimeType:#"image/png" fileName:#"iCon"];
Now i want to attach the table view which was already in my view to the body of the email page.
help me..
Thanks in advance
AFAIK it's not possible to add UITableView to email. You have two options, first - generate html, and content of table view as html table, or second - render content of this UITableView in PDF file, and next add this pdf to email.

iPhone: How to Display Text from UIWebView HTML Document in a UITextView

I have an RSS feed that gets arranged in a UITableView which lets the user select a story that loads in a UIWebView. However, I'd like to stop using the UIWebView and just use a UITextView or UILabel.
This png is what I am trying to do (just display the various text aspects of a news story):
I have tried using:
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];
and assigning the string to a UILabel but it doesn't work from where I am implementing it in webViewDidFinishLoad (--is that not the proper place?). I get a blank textView and normal webView.
If I overlay a UITextView on top of a UIWebView on its own (that is, a webView that just loads one page), the code posted above works displays the text fine. The problem arises when I try to process the RSS feed .
I've been stuck wondering why this doesn't work as it should for a few days now. If you have a better, more efficient way of doing it then placing the code in webViewDidFinishLoad, please let me know! Does it go in my didSelectRowAtIndexPath?
Thank you very much in advance!
I think the you should first log the string returned by :
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];
... in the case of the RSS feed to make sure that you are getting something back. It's possible the RSS page doesn't have the same javascript components and that it returns an empty string.
Once you've confirmed that, then it becomes a simple matter of getting it to display properly in the text view.
If the NSString you want to display is not empty, try to do something like this in the webViewDidFinishLoad method:
[yourUILabel performSelectorOnMainThread:#selector(setText:) withObject:[NSString stringWithFormat:#"bla bla %#", #"more bla"] waitUntilDone:YES];
The main thread of an iphone app is responsible for drawing components, that is why your label doesn't show your text.
You could also try setting setNeedsDisplay: to true
Also, the UILabel will not preserve the HTML format. It will display it as just text.
You could try the following:
NSString *htmlContent = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.innerHTML;"];
NSString *htmlContent = [webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML;"];
NSString *htmlContent = [webView stringByEvaluatingJavaScriptFromString:#"document.body.innerText;"];
You lose out on formatting information with the last line of code.