Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
조회 수 952 댓글 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"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
117 | Develop | [vc++] 게임 소스 등.. ㅋㅋ | hooni | 2013.04.23 | 18347 |
116 | Develop | [vim] vim 명령으로  문자 제거하기 (remove 65279 bomb) | hooni | 2021.02.03 | 1161 |
115 | System/OS | [virtualbox] VirtualBox에 Ubuntu 설치하기 | hooni | 2019.11.22 | 910 |
114 | Develop | [web] URL 인코딩 방법.. 테이블.. ㅋㅋ | hooni | 2013.04.23 | 7142 |
113 | Develop | [web] 더 빠른 웹을 위한 프로토콜, 'HTTP/2' | hooni | 2014.10.20 | 1641 |
112 | Develop | [web] 웹 연동 프로그램 모음.. | hooni | 2013.04.23 | 6960 |
111 | System/OS | [web] 웹서비스 취약점 자료.. (논문첨부) | hooni | 2003.04.23 | 17940 |
110 | Etc | [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다 | hooni | 2013.08.16 | 19808 |
109 | System/OS | [windows] 98/ME 속도 빠르게 튜닝(부팅,메모리,레지스터) | hooni | 2003.04.23 | 50443 |
108 | System/OS | [windows] 도스 사용 팁 | hooni | 2003.04.23 | 17810 |
107 | System/OS | [windows] 배치(bat)파일 제작 방법 | hooni | 2003.04.23 | 17006 |
106 | System/OS | [windows] 여러가지 활용 팁 | hooni | 2003.04.23 | 19973 |