Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
조회 수 937 댓글 0
JS 파일을 프로젝트로 추가하고 UIWebView 딜리게이트를 처리하는 내용
- (void)webViewDidStartLoad:(UIWebView *)webView{ ... // JS파일들을 동적으로 추가하는 내용의 함수 호출 [self injectJSCodes]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { .... // JS 함수가 잘 로드되고 실행 되는지 확인 NSString *jsString1 = @"picomax.alert('2100411931200932');"; [_webView stringByEvaluatingJavaScriptFromString:jsString1]; NSString *jsString2 = @"OcbiOSJS.showBarcodeScanPopup('2100411931200932');"; [_webView stringByEvaluatingJavaScriptFromString:jsString2]; } - (void)injectJSWithPath:(NSString *)path { //현재 프로젝트의 리소스 파일의 경로 얻기. //NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; //NSString *path = [[NSBundle mainBundle] pathForResource:@"OcbiOSJS" ofType:@"js"]; NSLog(@"js path : %@", path); NSString *jsString = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; [_webView stringByEvaluatingJavaScriptFromString:jsString]; } - (void)injectJSCodes { [self injectJSWithPath:[[NSBundle mainBundle] pathForResource:@"OcbiOSJS" ofType:@"js"]]; [self injectJSWithPath:[[NSBundle mainBundle] pathForResource:@"OcbiOSTitleViewJS" ofType:@"js"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
757 | Develop | [ios] 구분자로 문자열 자르기 (split) | hooni | 2013.04.23 | 26268 |
756 | Develop | [node.js] nodejs 기본 설치 | hooni | 2013.04.23 | 26250 |
755 | Develop | [python] DJI Tello 드론 코딩 (프로그래밍) 58 | hooni | 2018.03.04 | 25716 |
754 | Develop | GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기) 4 | hooni | 2013.07.06 | 25315 |
753 | Develop | [c#] 웹문서 소스(html) 긁어오기 | hooni | 2013.04.23 | 24504 |
752 | Develop | [c++] MD5 구현 소스.. 퍼움.. | hooni | 2013.04.23 | 24068 |
751 | Develop | [ios] 아이폰 개발 총정리.. | hooni | 2013.04.23 | 23861 |
750 | Develop | [pdf] GPS의 동작 원리 ㅎㅎ | hooni | 2013.04.23 | 23830 |
749 | Develop | [c] 다중연결 서버 만들기 #4 - thread 사용 | hooni | 2013.04.23 | 23701 |
748 | Develop | [c#] 비동기 통신 샘플 코드 ㅎㅎ | hooni | 2013.04.23 | 23631 |
747 | Develop | GCM 사용하기 2 (단말에 GCM 구현하기) | hooni | 2013.07.06 | 23248 |
746 | Develop | [ios] UIColor 지정에서 RGB define ㅎㅎ | hooni | 2013.04.23 | 22912 |