我有一个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 …Run Code Online (Sandbox Code Playgroud) 我刚刚在iOS7中发现了一个新的框架:JavaScriptCore.
它看起来很棒,但是如何访问运行时/上下文UIWebView?
我有一个IOS应用程序,里面有一个Web浏览器.
显示此Web浏览器时,它会导航到Internet上的页面,例如http://myexample.com/myiosapp.
是否可以在此网站上放置一个javascript代码,当下载到手机时,它与本机应用程序进行通信?它可以调用Objective-C方法,还是写一些东西到这个应用程序的存储空间?
防爆.myexample.com/myios应用上托管的代码:
function saveSomeString() {
xcode.Save("somestring");
}
Run Code Online (Sandbox Code Playgroud)
应调用名为Save的Objective-C函数,该函数将传入的字符串参数保存到本地存储.
ios ×3
objective-c ×3
uiwebview ×2
cocoa-touch ×1
ios7 ×1
iphone ×1
javascript ×1
polygons ×1
uibezierpath ×1