현재 HTML 파일을 성공적으로로드하는 웹보기가 있습니다.네이티브 iOS 앱의 변수로 자바 함수 호출
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="inlineAttachmentTemplateStyling.css">
<script>
function myFunction()
{
document.write("Hello from my html file!!!!");
}
</script>
</head>
<body id="body">
<div id="container">
<img id="testImage" src="fauxImageAttachment2.JPG" />
</div><!-- #container -->
</body>
</html>
이 이미지가 웹보기에 나타납니다에서 작동 :처럼 외모가
- (EmailView *)loadHTMLIntoEmailView:(EmailView *)emailView
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"inlineAttachmentTemplate" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:path];
NSString *resourceURL = [[NSBundle mainBundle] resourcePath];
resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
resourceURL = [resourceURL stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"file:/%@//",resourceURL]];
[emailView.webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseURL];
return emailView;
}
HTML 파일 :처럼 나는 그가하는이 방법이 보인다. 함수에서 document.write를 가져와 스크립트 태그 안에 직접 배치하면 텍스트가 webview에 나타납니다. 그러나 텍스트를 webview에 표시 할 수있는 함수 (내 Objective C 메서드에서)를 호출 할 수 있어야하며 궁극적으로이 함수에 일부 변수를 전달해야합니다. 현재 자바 스크립트 함수를 호출하는 방법을 알지 못합니다.
나는,이 예에서 Can you call a javascript function from native code (not in a callback) using PhoneGap and iOS?을보고, 나의 목표 C 메서드에 다음 줄을 추가하는 시도 :[emailView.webView stringByEvaluatingJavaScriptFromString:@"myFunction()"];
그러나이 함수를 호출하지 않습니다 ... 또는 적어도 텍스트가 표시되지 않습니다 webview.
저는 초심자 프로그래머이고 자바 스크립트에 대해 많이 알지 못합니다. 내가 잘못하고있는 것을 강조 할 수 있습니까?