我正在尝试获取自定义网址方案以在应用程序内打开网址。所以url方案将是“example:// confirm?1234”,我想将查询字符串用作UIWebView的url的一部分。这样就可以使UIWebView打开“http://www.example.com/confirm?1234”。这是在AppDelegate中完成的,所以我在控制FirstViewController UIWebView时遇到了问题。任何帮助都会被爱。
- (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];
}
答案 0 :(得分:0)
您需要一种字符串格式来构建新网址:
NSLog(@"String: %@", [url query]);
NSString *web = [NSString stringWithFormat:@"http://www.example.com/confirm?%@", [url query]];
NSURL *url = [NSURL URLWithString:web];
答案 1 :(得分:0)
我明白了。如果其他人有类似的问题,下面的代码会有所帮助。
- (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];
}