私はiPhoneの開発には初めてです。iphoneのwebviewでダウンロードしたファイルを開く
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = [paths objectAtIndex:0];
NSString *fileLoc = [basePath stringByAppendingString:@"/filename.pdf"];
NSData *fileData = [self decodeBase64WithString:soapResults];
[fileData writeToFile:fileLoc atomically:YES];
そして、私のファイルのパスにあります:私は、私は、コードを次のようにWebサービスを使用してファイルをダウンロードしていたにiphoneのアプリケーションが開発しています/ユーザ/ myusernameと指定/ライブラリ/ Application Support/iPhoneシミュレータ/ 4.0 /アプリケーション/ 7A627E64-DEAB-40FA-BE04-35ED50580B65/filename.pdf
どのようにすればこのファイルをuiwebviewで開くことができますか?私はこれを試してみました:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = [paths objectAtIndex:0];
NSString *fileLoc = [basePath stringByAppendingString:@"/filename"];
[self loadDocument:fileLoc inView:mywebview];
マイloadDocument方法は次のとおりです。
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
しかし、それはエラーを示す...私は場所が問題だと思う...どのように私はシミュレータでだけでなく、パスを見つけることができます信号装置
助けてください...
ありがとうございます...それは働いた... – itdeeps
元のデバイスのために、この同じファイルの場所が動作しますか? – itdeeps
はい。 'NSSearchPathForDirectoriesInDomains'は、デバイスとシミュレータの両方に適切なパスを返します。 – cduhn