WebView가 있고 JavaScript에서 Objective-C로보기를 호출하고 싶습니다. 누군가 내가 이것을 어떻게 할 수 있는지 알고 있습니까?Javascript에서 Objective-C를 호출하는 방법?
- (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.
}
그리고 자바 스크립트 :
나는 나의의 ViewController이 코드가
function store(event)
{
document.location = "myapp:" + "myfunction:" + param1 + ":" + param2;
}
을하지만 아무 반응이 없습니다.
는 https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/JavaScriptFromObjC.html이 URL를 시도? – kamleshwar
[Javascript에서 Objective C 메소드를 호출하고 iOS의 Javascript로 데이터를 보내는 방법은?] (http://stackoverflow.com/questions/9826792/how-to-invoke-objective-c-method-from- javascript 및 send-back-data-to-javascrip) – zekel
Sixten Otto의 응답에 대한 자세한 예제는 http://stackoverflow.com/questions/21927612/call-objective-c-method-from-javascript/ 25465329 # 25465329 –