3

I would like to implement a custom URL scheme similar to how mailto works in Safari. In my html I have a link to my custom scheme (e.g., myapp://parms) which will call my app that has the myapp scheme defined. When myapp is done, I want to return to the Safari browser page. If you have a 'mailto:', the mail app has a cancel button. If you push that, or do the send, when done it goes away and the Safari page is there.

I know I am not supposed to kill my app. If I try, it goes back to home and not Safari anyway. How can I have my custom scheme app go away (hide?) when done so the calling app is back?

sjay
  • 101
  • 1
  • 4

2 Answers2

4

You could have the scheme specify a callback URL, which you open when you finish performing your task. For example,

myapp://dosomeaction?callback=http://referring-site.com

Then you would simply read the callback URL and use openURL: to go there. You could even add some extra parameters to indicate success/failure to the caller.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • The problem with this is the web page that calls the custom scheme is a form and I want to call the custom app from the form and return and I cannot loose all the data on the form. Invoking the browser again would loose any of the data already entered on the form. The way the mailto: is handled is exactly what I would like to do. – sjay Aug 07 '11 at 06:40
  • You can't do it exactly like mailto: because that's handled by the operating system and uses a modal MFMailComposeViewController. There's no way for you to display your app in the same way, you can only switch to it. – jtbandes Aug 08 '11 at 08:54
3

Your best bet here would be to pass the URL that you want to return to in the URL with the custom scheme. In other words, you would URL encode the 'callback' URL and place it as an element in the URL used to open your application.

When your application completes its tasks, then it uses this data that it received when it was opened to open the URL again using the [[UIApplication sharedApplication] openURL:yourURL] method.

dtuckernet
  • 7,817
  • 5
  • 39
  • 54