Ich habe ein Webview, in dem ich Online-Chat öffnen muss, wenn es geladen wird. Ich habe einen JavaScript-Code für den Online-Chat. Ich bin verwirrt, wie kann ich es benutzen. Ich habe versucht, Apple Website zu öffnen funktioniert gut, aber wie kann ich Javascript-Code in Objective c verwenden. Ich bin ziemlich neu in der Sprache und das ist das erste Mal, dass ich das benutze. Ich habe JavaScript-Code in einem Ordner hinzugefügt und es dem Ressourcenordner in meiner App hinzugefügt.Wie benutzt man JavaScript in Ziel C in iOS?
Antwort
Versuchen Sie dies.
NSString *scriptURL = [[NSBundle mainBundle] pathForResource:@"JavaScript" ofType:@"js"];
NSString *scriptContent = [NSString stringWithContentsOfFile:scriptURL encoding:NSUTF8StringEncoding error:nil];
[wkWebView evaluateJavaScript: scriptContent completionHandler:^(id _Nullable content, NSError * _Nullable error)
{
if (error) {
NSLog(@"Error: %@",error);
return;
}
NSLog(@"Content: %@",content);
}];
Kasse the apple doc. Es wird dir mehr helfen.
Hier ist the best example Skript in WebView zu verwenden.
Das ist etwas, das Sie in Ihrem Code verwenden können:
NSString *path;
NSBundle *thisBundle = [NSBundle mainBundle];
path = [thisBundle pathForResource:@"first" ofType:@"html"];
NSURL *instructionsURL = [NSURL fileURLWithPath:path];
[webView loadRequest:[NSURLRequest requestWithURL:instructionsURL]];
NSString * jsCallBack = [NSString stringWithFormat:@"myFunction()"];
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
[webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];
Ich habe HTML-Datei und JS-Datei in meinem Ordner Projektressourcen. @Nirmalsinh –
https://stackoverflow.com/questions/5733883/loading-javascript-into-a-uiwebview-from-resources – Nirmalsinh
Überprüfen Sie die obige Antwort. Es wird dir helfen. – Nirmalsinh
- 1. Wie verwendet man Namespaces in iOS-Ziel-C-Code?
- 2. Wie benutzt man onPageLoad in Javascript?
- 3. Wie benutzt man CORS in Javascript?
- 4. Wie man LKW-Bild in CCSprite bei Berührung in iOS Ziel c drehen?
- 5. Instruktionsbildschirm ios Ziel c
- 6. Zugriffskontakte iOS-Ziel c
- 7. Wie man Gabel in C benutzt
- 8. Wie benutzt man/unique_lock in C++?
- 9. Wie benutzt man [DllImport ("")] in C#?
- 10. Customize NavigationBar in IOS Ziel c Anwendung
- 11. wie man characterSet in Ziel c drucken?
- 12. Wie validiere ich ein TextField in Ziel C (ios)
- 13. Cluster in MapKit IOS Ziel C
- 14. AutoComplete TextField in iOS mit Ziel C
- 15. wie in App-Kauf ios 10 in Ziel c implementieren
- 16. Wie XMPP-Server über XMPPFramework in ios in Ziel c
- 17. Wie benutzt man in gfortran?
- 18. Ziel c Wie man AES von Android auf iOS abbildet
- 19. wie in Ziel c
- 20. Wie verwendet man CNContactPickerViewController mit Ziel c?
- 21. HTML in Ziel C
- 22. JavaScript ist Funktion in Ziel-C
- 23. Wie benutzt man VBOs in GLKit für iOS?
- 24. wie man Funktion für diesen Code in Ziel c
- 25. Wie UIButton deaktivieren, die programmatisch in iOS Ziel c erstellt
- 26. Wie Sendeanforderung mit mehrteiligen Formulardaten in iOS-Ziel c senden?
- 27. Wie Bild und Text in Ziel c ios teilen
- 28. Wie benutzt man findElementsByIosNsPredicate?
- 29. Wie man Javascript ODER Bediener benutzt?
- 30. Dekodierung in Kenji auf ios NSString Ziel c mit
, was darin ist wKWebView seine zeigt Fehler. @ovo –
Hier ist [WKWebView] (https://developer.apple.com/documentation/webkit/wkwebview) doc. – ovo