Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
조회 수 1064 댓글 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"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1101 | Develop | [android] ListView+ArrayAdapter 테스트 | hooni | 2013.04.23 | 43945 |
1100 | Develop |
[android] N-Puzzle 게임
![]() |
hooni | 2015.07.09 | 949 |
1099 | Develop | [android] SQLiteOpenHelper를 이용한 DBManager | hooni | 2017.06.14 | 2165 |
1098 | Develop |
[android] SurfaceView를 이용한 애니메이션 ㅎㅎ
![]() |
hooni | 2013.04.23 | 57753 |
1097 | PPT |
[android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료
![]() |
hooni | 2013.04.23 | 75703 |
1096 | Develop | [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) | hooni | 2013.04.23 | 20476 |
1095 | Develop |
[android] 가속도 센서를 이용한 흔듦(Shake) 감지
![]() |
hooni | 2014.11.04 | 1997 |
1094 | Develop | [android] 간단한 SQLIite 예제 | hooni | 2017.06.14 | 1450 |
1093 | Develop |
[android] 개발 환경 세팅 따라하기 ㅋㅋ
![]() |
hooni | 2013.04.23 | 40453 |
1092 | Develop |
[android] 단일 Thread 환경의 안드로이드에서 Handler를 사용
![]() |
hooni | 2013.04.23 | 26562 |
1091 | Develop | [android] 디바이스(시뮬레이터) hosts 파일 수정하기 | hooni | 2013.04.23 | 31119 |
1090 | Develop | [android] 딜레이를 구현하기 위한 꼼수 | hooni | 2016.11.24 | 1071 |