Develop
2015.02.10 18:08
[ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기
조회 수 1078 댓글 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"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
105 | Develop | [ios] NSString, RegularExpression Find/Replace | hooni | 2017.04.14 | 959 |
104 | Develop | [ios] Facebook SDK 로그인 설명 | hooni | 2017.04.19 | 1359 |
103 | Etc | 사이버보안실무 시험. | hooni | 2017.04.20 | 0 |
102 | Develop | [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙) | hooni | 2017.05.11 | 1292 |
101 | Develop | 리팩토링 계획안 | hooni | 2017.05.15 | 878 |
100 | System/OS | [windows] 윈도우즈 콘솔에서 정품인증 하는 방법 | hooni | 2017.05.24 | 5664 |
99 | Develop | 사이버보안실무 발표자료 (2017.06.08) | hooni | 2017.06.05 | 1363 |
98 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 894 |
97 | Develop | [android] 간단한 SQLIite 예제 | hooni | 2017.06.14 | 1473 |
96 | Develop | [android] SQLiteOpenHelper를 이용한 DBManager | hooni | 2017.06.14 | 2191 |
95 | Etc | IT감사 기법 시험 | hooni | 2017.06.14 | 1629 |
94 | Develop | [coding] Find all anagrams in a string | hooni | 2017.06.27 | 1301 |