如何从Javascript调用Object-C?
我有一个WebView,我想从JavaScript调用Object-C中的一个视图。有人知道我该怎么做吗?
我的ViewController中有以下代码:-(BOOL)webView:(UIWebView*)webView2
shouldStartLoadWithRequest:(NSURLRequest*)request
navigationType:(UIWebViewNavigationType)navigationType{
NSString*requestString=[[requestURL]absoluteString];
NSArray*components=[requestStringcomponentsSeparatedByString:@":"];
if([componentscount]>1&&
[(NSString*)[componentsobjectAtIndex:0]isEqualToString:@"myapp"]){
if([(NSString*)[componentsobjectAtIndex:1]isEqualToString:@"myfunction"])
{
NSLog([componentsobjectAtIndex:2]);[[Airshipshared]displayStoreFront];//
NSLog([componentsobjectAtIndex:3]);//param2
//CallyourmethodinObjective-Cmethodusingtheabove...
}
returnNO;
}
returnYES;//ReturnYEStomakesureregularnavigationworksasexpected.}
在Javascript中:functionstore(event){
document.location="myapp:"+"myfunction:"+param1+":"+param2;}
但什么都没发生。