Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
Views 1085 Comment 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"]]; }
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
781 | Develop | [swift] 실행시간 측정하기 | hooni | 2021.09.14 | 865 |
780 | Develop | [swift] UIView에서 subview 찾기 | hooni | 2022.12.09 | 2129 |
779 | Develop | [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 | hooni | 2021.01.29 | 1610 |
778 | Develop | [swift] NotificationCenter 간단 예제 | hooni | 2021.01.27 | 8354 |
777 | Develop | [spring] 스프링 IoC/DI | hooni | 2013.04.23 | 11413 |
776 | Develop | [sh] 쉘스크립트 if 비교 연산 | hooni | 2020.05.26 | 61119 |
775 | Develop | [sh] html 안에 있는 img 다운 받는 쉘 스크립트 | hooni | 2020.05.26 | 768 |
774 | Develop | [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) | hooni | 2019.12.06 | 1850 |
773 | Develop | [python] 파이썬 공부하는 사이트~ | hooni | 2013.11.12 | 10898 |
772 | Develop | [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) | hooni | 2019.11.22 | 1710 |
771 | Develop | [python] 애니팡, 캔디팡 매크로 | hooni | 2013.09.06 | 18221 |
770 | Develop | [python] DJI Tello 드론 코딩 (프로그래밍) 58 | hooni | 2018.03.04 | 28812 |