電話のかけ方は、Objective-C方式からJavascriptココア/WebKitたします。
-
01-07-2019 - |
質問
いココアのアプリを使用したWebViewを表示ドキュメントを編集するには、インターフェース。方法を教えてくださいく呼Objective-C方式からJavascript関数内で、HTMLフ?
解決
この文書で developer.apple.com.
他のヒント
だんなアプリケーションすことが必要なのかをUIWebViewDelegate法shouldStartLoadWithRequest:
このapi http://code.google.com/p/jsbridge-to-cocoa/ います。とても軽量化を達成しています。
れていな緑色、Appleのドキュメントには使用不可能に思っていたの概念実証を呼び出した目的地の方法からjavascriptではその逆とココアのものに比べて簡単になりました。
最初に確認してくださいおwebviewをsetFrameLoadDelegate:
[testWinWebView setFrameLoadDelegate:self];
必要なものwebviewを見特定のオブジェクトでのロード:
- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowScriptObject forFrame:(WebFrame *)frame {
//add the controller to the script environment
//the "ObjCConnector" object will now be available to JavaScript
[windowScriptObject setValue:self forKey:@"ObjCConnector"];
}
その後、事業のコミュニケーション:
// a few methods to log activity
- (void)acceptJavaScriptFunctionOne:(NSString*) logText {
NSLog(@"acceptJavaScriptFunctionOne: %@",logText);
}
- (void)acceptJavaScriptFunctionTwo:(NSString*) logText {
NSLog(@"acceptJavaScriptFunctionTwo: %@",logText);
}
//this returns a nice name for the method in the JavaScript environment
+(NSString*)webScriptNameForSelector:(SEL)sel {
NSLog(@"%@ received %@ with sel='%@'", self, NSStringFromSelector(_cmd), NSStringFromSelector(sel));
if(sel == @selector(acceptJavaScriptFunctionOne:))
return @"functionOne"; // this is what you're sending in from JS to map to above line
if(sel == @selector(acceptJavaScriptFunctionTwo:))
return @"functionTwo"; // this is what you're sending in from JS to map to above line
return nil;
}
//this allows JavaScript to call the -logJavaScriptString: method
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)sel {
NSLog(@"isSelectorExcludedFromWebScript: %@", NSStringFromSelector(sel));
if(sel == @selector(acceptJavaScriptFunctionOne:) ||
sel == @selector(acceptJavaScriptFunctionTwo:))
return NO;
return YES;
}
その場合には複数の方法で行きたい話をする必要はありませ対象外にisSelectorExcludedFromWebScript方法の必要があるのjavascriptコの地図のObjC法webScriptNameForSelector.
フルプロジェクトのファイル:https://github.com/bytestudios/JS-function-and-ObjC-method-connector
ビル街は潰れてほしい。用NimbleKit.で呼びObjective-Cの機能からです。
所属していません StackOverflow