3

In my application, I have a webview which loads up a page that contains both normal links and custom URL schemes, such as myapp://id=1234.

Right now, I am trying to trap the request within this function:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request 
 navigationType:(UIWebViewNavigationType)navigationType{

    NSLog(@"NSURLRequest = %@", [[request URL] absoluteString]);

}

Printing out the url as above gives me this:

http://localhost:8888/myapp://id=1234

Which is my localhost setup on MAMP with the custom URL appended to the URL.

I had hoped that I could use [request scheme] directly, but in this case now, it simply returns "http". Is there a way that I can handle custom URL schemes from within my own app?

At this point, I would like to be able to do the following:

  1. User is on the webview
  2. User taps the custom url link ( myapp://id=1234 )
  3. My app handles the custom url and directs the user to another page ( http://www.someotherpage.com/?id=1234 )

Thank you!

kurisukun
  • 3,149
  • 5
  • 37
  • 69

2 Answers2

0

When a URL has a double-slash following the colon, like yours does, the next part is supposed to look like userinfo@hostname:port (both userinfo@ and :port can be omitted). Since id=1234 does not look like a hostname, the URL parser is not recognizing your URL as an absolute URL. So the URL parser treats it as a relative URL.

Try changing your URL syntax to either myapp:id=1234 or myapp:///id=1234.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Thank you, unfortunately, using the scheme still returns http. Would it be bad practice to simply use string compares to figure out if the "myapp://" exists, then perform an action? – kurisukun Nov 24 '11 at 08:22
0

I guess you shall declare any custom URL scheme as handled by your application.

Check reference

Sylvain G.
  • 508
  • 2
  • 9