【发布时间】:2010-12-12 08:37:00
【问题描述】:
我有一个 WebView,我想从 JavaScript 调用 Objective-C 中的一个视图。有人知道我该怎么做吗?
我的 ViewController 中有这段代码:
- (BOOL)webView:(UIWebView *)webView2
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSString *requestString = [[request URL] absoluteString];
NSArray *components = [requestString componentsSeparatedByString:@":"];
if ([components count] > 1 &&
[(NSString *)[components objectAtIndex:0] isEqualToString:@"myapp"]) {
if([(NSString *)[components objectAtIndex:1] isEqualToString:@"myfunction"])
{
NSLog([components objectAtIndex:2]); [[Airship shared] displayStoreFront]; //<- This is the code to open the Store
NSLog([components objectAtIndex:3]); // param2
// Call your method in Objective-C method using the above...
}
return NO;
}
return YES; // Return YES to make sure regular navigation works as expected.
}
在 Javascript 中:
function store(event)
{
document.location = "myapp:" + "myfunction:" + param1 + ":" + param2;
}
但什么也没发生。
【问题讨论】:
-
Sixten Otto 在此处回复的详细示例:stackoverflow.com/questions/21927612/…
标签: iphone cocoa-touch uiwebview