如何从Javascript调用Object-C?我有一个WebView,我想从JavaScript调用Object-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;}但什么都没发生。
3 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
UIWebView
UIWebViewDelegate
webView:shouldStartLoadWithRequest:navigationType:
window.location = "fake://myApp/something_happened:param1:param2:param3";
NO
performSelector
.
小唯快跑啊
TA贡献1863条经验 获得超2个赞
function execute(url) { var iframe = document.createElement("IFRAME"); iframe.setAttribute("src", url); document.documentElement.appendChild(iframe); iframe.parentNode.removeChild(iframe); iframe = null;}
execute
添加回答
举报
0/150
提交
取消