0

I am trying to get a custom url scheme to open a url inside the application. So the url scheme would be "example://confirm?1234" which I would like to use the query string as part of a url for a UIWebView. So that would make the UIWebView open "http://www.example.com/confirm?1234". This is being done in the AppDelegate so I am also having an issue controlling the FirstViewController UIWebView. Any help would be loved.

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        sourceApplication:(NSString *)sourceApplication
        annotation:(id)annotation {
    NSLog(@"String: %@", [url query]);  
    NSString *web = @"http://www.example.com/confirm?[url query]";
    NSURL *url = [NSURL URLWithString:web];
    NSURLRequest *requestUrl = [NSURLRequest requestWithURL:url];
    [webView loadRequest:requestUrl];
}
Mike Abdullah
  • 14,933
  • 2
  • 50
  • 75
Bob Stone
  • 39
  • 1
  • 5

2 Answers2

0

You need a string format to build the new URL:

NSLog(@"String: %@", [url query]);  
NSString *web = [NSString stringWithFormat:@"http://www.example.com/confirm?%@", [url query]];
NSURL *url = [NSURL URLWithString:web];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

I figured it out. In case anyone else have a similar issues the code below helps.

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
 sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {
 if ([[url host] isEqualToString:@"confirm"]) {
 NSLog(@"String: %@", [url query]);
 NSString *urlAddress = [NSString stringWithFormat:@"http://www.example.com/confirm.php?key=%@", [url query]];
NSURL *url2 = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
 [webView loadRequest:requestObj];
 }
Bob Stone
  • 39
  • 1
  • 5