2012-08-06 76 views
-1

我想下載文件使用NSUrlConnection,將文件保存到文件目錄,然後在web視圖中打開它。iPhone - 從互聯網上下載文件,並保存到文件direcory

我使用的代碼:

- (IBAction)down:(id)sender { 
// create the request 
url = [[NSURL alloc]initWithString:urlbox.text]; 
NSLog(@"%@",url); 

NSURLRequest *theRequest=[NSURLRequest requestWithURL:url 
              cachePolicy:NSURLRequestUseProtocolCachePolicy 
             timeoutInterval:60.0]; 
NSURLConnection *theConnection; 
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
if (theConnection) { 

    NSMutableData *receivedData; 
    receivedData=[NSMutableData data]; 

} 

下載文件。如果有人可以給我一些代碼來保存文件並在webview中打開它,那會很棒。

感謝

+2

你已經試過了什麼?你有什麼問題嗎?這不是一個按需代碼服務。 – occulus 2012-08-06 20:49:17

+0

我聽說過這個「谷歌」網站有一個偉大的代碼庫 – 2012-08-06 20:56:30

回答

0

看一看MGPRemoteAssetController這是一個插件,我使用了基於NSURLConnection

更重要的是,您可以跟蹤MGPRemoteAssetDownloader的工作方式。這是一個很好的示例代碼。

+0

好吧,我會檢查出來 – benjih555 2012-08-07 15:53:09

0

獲取Vandad Nahavandipoor(O'Reilly)編寫的「iOS編程指南」一書中的示例和代碼,以完成您想要的工作。 Matt Neuburg(也是O'Reilly)編寫的「編程iOS 5」也很有幫助。

相關問題