Getting user's form data on iOS - iphone

I need to have my users fill out a form, and send me the information. Nothing fancy, just their name and email, and they'd be doing it willingly.
I looked into emailing the information to my account, but it seems like you have to pop the MFMailComposeViewController and let the user submit an email -- and I don't want to bother them with that.
I also tried a simple mailto url, like this:
NSString *url = #"mailto:example#example.com?&subject=Greetings from Cupertino!&body=Wish you were here!";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
But it doesn't work on my simulator, or my iPhone, which is 4s with iOS 6.
I also looked into creating a google doc, and have the application send the user's info to its URL, but I'm assuming the result would be similar to the mailto URL?
So is there a good, simple way to do it?

So is there a good, simple way to do it?
Sure -- but not using mail. Use HTTP instead, and POST the data to a web server. If you need to collect the results by mail, you could easily create an e-mail message on the server and send from there, but it seems more likely that you'll just want to add the information to a database directly.
To use HTTP, you'll create a NSURLRequest with the relevant parameters and then send it using NSURLConnection. If you don't feel like digging into the URL loading system that iOS provides, there are a number of wrapper libraries that make it even easier. But for what you want to do, using NSURLConnection directly will be pretty straightforward.

Maybe you should have a look at these links :-
How to send mail from iphone app without showing MFMailComposeViewController?
Send mail without MFMailComposeViewController
Sending Email without using MFMailComposeViewController
MFMailComposer send email without presenting view

Related

Swift 4, CorePlot, send chart via mail app (with MessageUI)

Can I somehow take the chart (which was made with CorePlot) from view and send it as a file to another person via mail app? I want to send mail with the help of MessageUI. I feel fine if just the picture will be sent.
Use the -imageOfLayer method to get a PNG of the graph or the -dataForPDFRepresentationOfLayer method to get a PDF and attach the resulting file to a message.

Characters getting cut off by Mail app when launching from within my app

I'm trying to set up a prefilled email for the user to send through the iphone native Mail application. The body of the email contains a link that the user wants to share.
My problem is that the link is getting cut off by the Mail app but when I print out the string in my app the whole link is there.
Here is a sample link:
http://sample.com/Start.asp?tqnm=xe2nbek92057479&bt=xg&o=100925&c=RB&p=2W7TvRx1
In the mail app the link shows up as:
http://sample.com/Start.asp?tqnm=xe2nbek92057479
I am using the standard code for launching the Mail app:
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
NSLog(#"Mail String: %#", mailString);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
I've also tried other string encodings but I either get the same result or the body of the email doesn't show up at all.
Any help would be really appreciated. I've been looking for the answer for a while and haven't found anything to even point me in the right direction.
I was able to solve it, I found this function
NSString* encodeToPercentEscapeString(NSString *string) {
return (NSString *)
CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef) string,
NULL,
(CFStringRef) #"!*'();:#&=+$,/?%#[]",
kCFStringEncodingUTF8);
Then I used that to encode the body, which took care of the ampersand case, which Matthias was referring to. Thank you Matthias for pointing me in the right direction.
This is perhaps more a work-around than an answer, but... You might consider using the MessageUI framework to send the mail directly from within your app. You can easily set the body of the mail without any encoding issues and it also a little bit nicer for the user (i.e. does not switch away from your application).
There are plenty of tutorials/code snippets on the web about how to do this. (I wrote this one a while ago Sending Mail from your App). Hope this helps!

how to send email using UIbarbuttonitem without using MFMailComposerViewController

I want to send email using rightBarButtonItem without using MFMailComposerViewController.
Is It possible to send email using barButtonItem?
Any Idea how to do this?
thanx in advance.
You'll find a fantastic code sample on the accepted answer here to send a background email:
Locking the Fields in MFMailComposeViewController
All you need to do is setup your rightBarButtonItem's target to fire a method containing this email code, and then populate the message contents etc using the information you want to send.
Hope this helps!
Set an action method for the right bar button item and thus, you can make a direct call to open the email client and compose a mail.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto://testmailer#somemail.com"]];
This is just a quick fix or may be something you were looking for!

iPhone: How do I securely transfer data from device to server

could someone please assist me, Im a newbie and haven't done this before.
I have an iPhone app which has a "cart" object. Once the user has made his selections, I want to send that info in an XML file to the server. I read that the iPhone libraries let you convert data into XML easily. But from what I understand the data has to be stored in an array or a dictionary. Is this true? For example, my "Cart" is an object that uses a array to store data internally but the "cart" itself has variables which are not stored in an array or dictionary.
Q) How can I convert the entire "cart" into something that can be transported as XML to my server?
Also, I am asking the customers to create a profile for each order but this will be done by Launching UIWebview directly on the web through an https connection. So no credit card info will be on the device.
Q) Whats the best way to link the profile on the web and the order which is on the device?
Could someone who has come across this issue please give me tips or links?
Thanks
Sending your data securely could be done with ssl.
Converting your cart to XML could be done with an XML Framework/lib, still you'll have to write the code for that. For example touchXML:
TouchXML is a lightweight replacement
for Cocoa's NSXML* cluster of classes.
It is based on the commonly available
Open Source libxml2 library.
Here is a nice tutorial.
Source has moved a bit, can be found here
To your second question: This is tricky and may get hacky. However if you don't want to switch to an API based way to login/create the account I'll have these ideas.
Check the "result" of webView with the UIWebViewDelegate protocol with the webViewDidFinishLoad: method. A "result" may be: successful creation of an account or successful login.
So you can access the body of the page with the NSURLRequest property of the webview. Or use something like this, using javascript:
NSString *html = [webView stringByEvaluatingJavaScriptFromString: #"document.body.innerHTML"];
You will have to do parsing though to look for something, for example a token which you can connect with the order for final checkout.
You also could have generated a unique order string on the device in the first place and sent it over initially for login/creation of profile to increase security a bit and pass it back for a check.
Part one: create a dictionary that represents the cart. For each variable, add a key with its variable name as the key, and the cart object's value for that variable as the object for that key.
Part two: that's a very open-ended question :-). That depends on how you identify the user at both ends; though of course that will depend on your security requirements. One option is to require your user logs in via the web site when they first launch the device, then store their user ID on the app on a particular device (preferably in a confidential fashion). Don't use that for any reason other than to track which user you think is at the device: authenticate again before each purchase, or other sensitive actions like viewing or changing account details. By the way depending on the way your ordering system works, you may prefer (or be required by Apple) to implement in-app purchase. That would actually take a lot of the complexity away from the problem, at the cost of Apple's 30% processing fee.
If you have specific questions about the security concerns of such a system, you would do well asking at security.stackexchange.com (I'm one of the pro tem moderators over there).
If you send an encrypted string to a URL like in the code below, then handle it in an ASPX page (.NET example) or you can use other languages on the server side. Then, for security, simply ignore anything that doesn't decrypt (basic encryption-decryption not shown)
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL
URLWithString:#"http://myzuresite.azurewebsites.net/test3.aspx?bigstring=dgrbthymgk"]];
[request setHTTPMethod:#"POST"];
[NSURLConnection connectionWithRequest:request delegate:self];}
Then, in the http://myazuresite.azurewebsites.net/test3.aspx page:
<%# Page Language="C#"%>
<html>
<head>
<title>Query Strings in ASP.NET: Page 2</title>
<script language="C#" runat="server">
</script>
</head>
<body>
<%
// retrieves query string values
string bigstring = Page.Request.QueryString["bigstring"];
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("Data Source=myazuresite.database.windows.net;Initial Catalog=db_name;Integrated Security=False;Persist Security info=False;User ID=your_id;Password=your_Password”);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT Scores (col1) VALUES (' "+name+" ')";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
%>
</body>
</html>
I handle the decryption in an insert trigger in SQL Server, ignore bad URL's, and this is VERY secure. I use encryption that includes time in some way.

How to customize MFMailComposeViewController so that i can make the "to" field as non-editable?

I am using MFMailComposeViewController for sending feedback in my app. It works fine. But the problem here is, the user can edit/delete the "to" address. I want to make it as a non-editable one. May be, the user can add some mail addresses in "to" field.
But he/she should not delete the feedback address (Here, it is "support#xxxx.com").
Here is my code...
MFMailComposeViewController *composeWindow = [[MFMailComposeViewController alloc] init];
composeWindow.mailComposeDelegate = self;
NSString *str = #"Subject of the feedback";
[composeWindow setSubject:[str stringByAppendingString:[[UIDevice currentDevice]systemVersion]]];
NSArray *toRecipients = [NSArray arrayWithObject: #"support#xxxx.com"];
[composeWindow setToRecipients:toRecipients];
[self presentModalViewController:composeWindow animated:YES];
[composeWindow release];
Thanks in Advance
Rajkanth
You can not customize MFMailComposeViewController to avoid editing. Apple forbids this, and the reason is quite simple: it is the user and not you that must decide exactly what to send, to whom etc. The same applies for the UI controller allowing to send SMS (text) messages. And, of course, Apple does not allows sending an email or SMS without explicit interaction with the user. It is the user that must validate and send the email or SMS message. The validation process include the ability to cancel the message or to change any single property at will, including the "to" recipients.
All the other answers are correct. You can not change the interface of the MFMailComposeViewController. But you have other possibilities. ;-)
Three20 SDK includes also an Mail Composer. Try it out. I think it should be that far changeable, that the "to" field is not editable anymore.
I hope my answer is helpful for you.
Sandro Meier
EDIT
Three20 SDK was discontinued a while ago. So you shouldn't use it anymore for new projects. I advise you to use NimbusKit instead. This is also recommended by the Three20 SDK team. Sadly it does not include a MailComposeViewController
From the Apple documentation:
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.