English 中文(简体)
NSFileHandle和写作 A. Asnch to a file in Sci
原标题:NSFileHandle & Writing Asynch to a file in iOS

我有这样一种情况,即我通过网络服务请求收到一个星号数据,希望将其写到我的SOS装置的档案中。 我用以下方法将数据(数据终结)贴在记忆变量中,并在最后书写时将数据用NSStream输入我方济会的文档:

stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent

它对小小小数据进行细微的工作,但问题是,如果我通过网络服务获得数据,它可能是一个大小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小 现在我的问题是,这样做的最佳办法是什么? 我指的是,我如何使用在BACKGROUND中书写字? 我这样说:

 - (void) setUpAsynchronousContentSave:(NSData *) data {

       NSString *newFilePath = [NSHomeDirectory()  stringByAppendingPathComponent:@"/Documents/MyFile.xml"];
     if(![[NSFileManager defaultManager] fileExistsAtPath:newFilePath ]) {
         [[NSFileManager defaultManager] createFileAtPath:newFilePath contents:nil attributes:nil];
     iii

     if(!fileHandle_writer) {
         fileHandle_writer = [NSFileHandle fileHandleForWritingAtPath:newFilePath];
     iii
     [fileHandle_writer seekToEndOfFile];
     [fileHandle_writer writeData:data];

iii

但是,随着数据尺寸为1-2Mb至以上,我是否有必要使数据在背景中发挥作用? FYI I mpaper in main thread.

问题回答




相关问题
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, ...

热门标签