1

I have an application that is about to go into testing that, upon reload after a crash, displays a UIAlertView with a text field that asks what the user was doing when the application crashed.

How can I take what the user puts in that UIAlertView text field and submit it to me? Email sounded great, but then they would have to leave the application for that and it seems inefficient. So something that would be more seamless.

Thanks in advance.

Baub
  • 5,004
  • 14
  • 56
  • 99

2 Answers2

4

They don’t have to leave the app to email you. Check out the MFMailComposeViewController class.

Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131
  • Well, what if they don't have email setup on the phone? – Baub Aug 17 '11 at 21:42
  • 1
    Then in this case, Apple provide a standard error in a UIAlertView - you can catch it yourself and check for Internet connectivity as well if you like, to stop the user from even getting this far. EDIT: If you check the accepted answer here, you can send an email without even involving the user with the To: Subject: fields etc and send it in the background, check here: http://stackoverflow.com/questions/6284599/mfmailcomposeviewcontroller-question-locking-the-fields – Luke Aug 17 '11 at 21:43
1

The easiest way to do this without resorting to e-mail is probably to build a simple web service which accepts an HTTP POST containing the details of the crash. Your web service can store those details in a database or flat file which you can access as needed.

POSTing from the iPhone to a web service is pretty easy. If you want to write the code yourself, I'd recommend checking out the NSURLConnection documentation. However, there's an even easier way to do it, as described in this answer: use the ASIHTTPRequest library to do the whole thing in just a few lines of code. This example code from the ASIHTTPRequest site describes how to POST a series of keys and values.

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

As for how to write the web service, here's a good tutorial on writing a simple PHP/MySQL web service, geared specifically towards iOS development. Of course, you will need a server for this, but hosting is cheap and this will definitely be the best way for you to collect data. (You could also use Google App Engine for free, but I've heard some bad things about App Engine's performance.)

Good luck!

Community
  • 1
  • 1
Mitch Lindgren
  • 2,120
  • 1
  • 18
  • 36
  • The app already posts, so I'll just re-implement that code in a different way and I'll create a separate server. Thanks! – Baub Aug 17 '11 at 21:55