NSString *imagePath = [[NSBundle mainBundle] resourcePath]; imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"]; imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; NSString * js = [NSString stringWithFormat:@"document.images[0].src='file:/%@//%@'",imagePath,@"test.png"]; [infoWebView stringByEvaluatingJavaScriptFromString:js]; NSString *path = [infoWebView stringByEvaluatingJavaScriptFromString:@"document.images[0].src"];
像一般情况下一样用file scheme访问就可以了