openURL + post data?

283 views
Skip to first unread message

Dan Grigsby

unread,
Dec 21, 2008, 2:58:18 PM12/21/08
to iphon...@googlegroups.com
I'd like to open have my app launch Safari, point Safari at a
particular URL, and include post data.

This is very easy to do without the post data:

NSURL *url = [NSURL URLWithString:@"http://www.unpossible.com"];
[[UIApplication sharedApplication] openURL:url];

Can't find any indication that it's possible to do what I'm after.
For my purposes, it's not acceptable to embed a WebKit UI; this needs
to launch Safari (which, of course, exits my app).

Damon Allison

unread,
Dec 22, 2008, 11:27:30 PM12/22/08
to iphon...@googlegroups.com
From my understanding, the only way to pass state between applications is through the code you posted.  Basically you have to cram everything into an NSURL object.  There are a few ways you could _simulate_ a form post:

1.  Put all state into querystring - a-la invoking mail.app with a to/subject/body.
2.  Post the form in cocoa, get back session or equivalent ID, which you use when launching safari with [UIApplication openURL].

If you want code to post a form via cocoa, let me know.  If you want to post an attachment, Sam has a multipart form poster he's using on one of our projects (actually I'm pretty sure Sam's code will cover both cases).  


Damon



- (IBAction) sendEmail:(id)sender {


NSString *to = @"da...@codemorphic.com";
NSString *subject = @"This is a test message";
NSString *body = @"<html><body><p>This is an example <b>email</b> message!<br><br>Thanks,<br>Damon</p></body></html>";
  to, subject, body];
NSURL *myURL = [NSURL URLWithString:[[NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@"
  to, subject, body] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:myURL];

Aaron

unread,
Jan 1, 2009, 10:31:44 AM1/1/09
to iphonedevmn
Dan,

Did you ever come up with a solution for this? I was thinking if you
aren't able to modify the server-side script(s) of what's being posted
to to support GET instead of POST, you could possibly have an
interstitial page that converts the GET query string parameters via
JavaScript and does a POST to the form you want on load. If you're
still looking for a solution, and want to explore that further let me
know.

Aaron

Dan Grigsby

unread,
Jan 2, 2009, 9:18:07 PM1/2/09
to iphon...@googlegroups.com
Aaron,

Thanks for the creative thinking. Without going into too many
details, this works with 3rd party sites and, no, doing the post from
the app and then launching the browser won't work. This'll all make
sense when I show you what it is. I can live with GET, so it's not
blocking.

Dan
Reply all
Reply to author
Forward
0 new messages