나는 phonegap 응용 프로그램을 가지고 있으며 매우 단순한 "Documents has exist"명령을 Documents 폴더에서 실행하려고합니다. 그리고 대부분 작동하고 있습니다. JS, 나는이 :객관적인 c에서 javascript로 변수를 반환합니다.
는fileDownloadMgr.fileexists("logo.png");
......
PixFileDownload.prototype.fileexists = function(filename) {
PhoneGap.exec("PixFileDownload.fileExists", filename);
};
그런 다음 목표 C에서, 내가 가진 :
-(BOOL) fileExists:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options;{
NSString * fileName = [paramArray objectAtIndex:0];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newFilePath = [documentsDirectory stringByAppendingString:[NSString stringWithFormat: @"/%@", fileName]];
BOOL isMyFileThere = [[NSFileManager defaultManager] fileExistsAtPath:newFilePath];
//i'm stuck here
}
나는 논리가 작업을 수행하고 BOOL이 설정되어 있는지 확인하기 위해 콘솔에이를 인쇄 할 NSLog를 사용할 수 있습니다 바르게. 하지만 자바 스크립트 세계에서 다시 변수가 필요합니다. 나는 stringByEvaluatingJavaScriptFromString을 알고 있지만 자바 스크립트 만 실행한다. 콜백 함수를 호출한다. 즉, 내가 여기에 필요하지, 난 (자바 스크립트)가 필요합니다 :
난 다시 자바 스크립트로 목표 C에서 해당 부울을 반환해야 할 일을var bool = fileDownloadMgr.fileexists("logo.png");
if(bool) alert('The file is there!!!!!!');
?
outis 나는 연속의 구현까지 여러분을 따라갑니다. 좀 더 명확한 예제를 제공해 주시겠습니까? 감사 – user7865437