嗨我想問一個很好的教程,向我展示如何使用目標C下載文件從URL到本地電話存儲我已經完成了以下同步,但我想使它同步異步從URL下載iPhone
NSString* docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* fileToDownload = @"data1.plist";
NSString* hostURLString = @"http://localhost/test";
hostURLString = [hostURLString stringByAppendingPathComponent: fileToDownload];
NSURL* pListURL = [NSURL URLWithString: hostURLString];
NSData* pListData = [NSData dataWithContentsOfURL: pListURL];
NSString* filePath = [docsDir stringByAppendingPathComponent: fileToDownload];
[pListData writeToFile: filePath atomically: NO];
NSString* Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *DataPath = [Path stringByAppendingPathComponent:@"data1.plist"];
任何建議
可能重複的[iPhone:與NSURL請求異步地下載數據,而不是\ [NSData的datawithContents ofURL \]](http://stackoverflow.com/questions/6012612/iphone-downloading-data-asynchronously- with-nsurl-request-as-opposite-to-nsdata) –
請嘗試以下鏈接。它可能會指導您創建和異步下載。 1. http://stackoverflow.com/questions/6820512/async-images-download-in-a-table 2. http://stackoverflow.com/questions/6012612/iphone-downloading-data-asynchronously-with- nsurl-request-as-opposition-to-nsdata – iOS