English 中文(简体)
将非同步数据附加到 ios 中的文件吗?
原标题:Asynchronous data append to file in ios?
< div class=" s- prose js- post-body" 项prop= "text" >

I 喜欢从网络路径下载图像。 但是, 由于存在大文件的风险, 我认为直接在文档目录中的文件中写入/ 附加部分NSdata块是一个好主意。 此选项是否可行? 我设置了一个无同步的 URLConnection 。 它会回拨一个代表 < precode> - ( 避免) 连接 : (NSURLonnection *) 连接 ReceiveData: (NSData *) data < p> method。 在这种方法中, 我愿意直接在磁盘中将已下载的“ 数据” 附加到文件 。 您能帮助一点吗? 如果这是不低 C 的空空空, 它将是完美的 。

最佳回答

我从未尝试过,但从这些苹果 docs ,我建议

@property (nonatomic,strong) NSFileHandle *handle;


//somewhere in a init or viewDidLoad
self.handle = [NSFileHandle fileHandleForUpdatingAtPath:filePath]

-(void)connection:(NSURLConnection *)connection 
   didReceiveData:(NSData *)data
{
    [handle seekToEndOfFile];
    [handle writeData:data];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    [self.handle closeFile]; 
} 

注意: 文件Path 必须是现有文件的有效路径, 有许多处理创建文件的邮件 。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签