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"]]; }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
517 | Develop | [android] 만화 어플 소스코드 | hooni | 2013.04.23 | 92923 |
516 | Develop | [ios] 미스터피자(Mr.pizza) 어플 | hooni | 2013.04.23 | 42693 |
515 | Develop | [iphone] 아이폰 어플 모음 ㅋㅋ | hooni | 2013.04.23 | 13707 |
514 | Develop | [android] 안드로이드 어플 모음 ㅎㅎ | hooni | 2013.04.23 | 16340 |
513 | Develop | [lego] 세그웨이 이것만 볼것.. ㅎㅎ | hooni | 2013.04.23 | 33585 |
512 | Develop | [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드) | hooni | 2013.04.23 | 72040 |
511 | Develop | [c#] Hashtable <-> Json (dll 포함) | hooni | 2013.04.23 | 80727 |
510 | Develop | [c#] Json 라이브러리 (System.Net.Json.dll) | hooni | 2013.04.23 | 58585 |
509 | Develop | [c#] 간단한 IPC 통신 예제 | hooni | 2013.04.23 | 63776 |
508 | Develop | [c#] 간단한 소켓통신 예제.. | hooni | 2013.04.23 | 26738 |
507 | Develop | [c#] 비동기 통신 샘플 코드 ㅎㅎ | hooni | 2013.04.23 | 23696 |
506 | Develop | [c#]업글 뉴 툴바 개인적으로 만든거.. (new) ㅋㅋ | hooni | 2013.04.23 | 7651 |