如何從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 回答

慕虎7371278
TA貢獻1802條經驗 獲得超4個贊
UIWebView
UIWebViewDelegate
webView:shouldStartLoadWithRequest:navigationType:
window.location = "fake://myApp/something_happened:param1:param2:param3";
NO
performSelector
.

catspeake
TA貢獻1111條經驗 獲得超0個贊
function execute(url) { var iframe = document.createElement("IFRAME"); iframe.setAttribute("src", url); document.documentElement.appendChild(iframe); iframe.parentNode.removeChild(iframe); iframe = null;}
execute
- 3 回答
- 0 關注
- 709 瀏覽
添加回答
舉報
0/150
提交
取消