0

I have problems to write big files on iPhone. My code works very well on the simulator, but on the iPhone nothing happens, respectively the files have size 0! I think it depends on the document directory, but i'm not sure.

for (int i = 1; i <= [_anzahl.text intValue]; i++)
{
NSString *book = [@"book" stringByAppendingFormat:@"%i", i];
NSLog(@"%@", book);
NSString *dummyFilePath = [[NSBundle mainBundle] resourcePath];
NSString  *filePath = [dummyFilePath stringByAppendingPathComponent:[NSString  stringWithFormat:@"%@", book]];
NSFileHandle *file = [NSFileHandle fileHandleForWritingAtPath:filePath];
if (file == nil) {
    [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
    file = [NSFileHandle fileHandleForWritingAtPath:filePath];
}
int zahl = [_sizeMB.text intValue];
[file seekToFileOffset:zahl * 1024 * 1024];
const unsigned char bytes[] = {1};
[file writeData:[NSData dataWithBytes:bytes length:sizeof(bytes)]];
    //Dateigröße ermitteln
    int fileSize = [file seekToEndOfFile];
    NSLog(@"book Size =%i" , fileSize) ;
}

Update for all newbies:

NSString *dummyFilePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
wolli911
  • 7
  • 5
  • An app's resource bundle is read-only on real devices. Your code makes no attempt to write to the Documents folder. – rmaddy Feb 05 '17 at 17:32
  • Thanks for comment! I know this answer, but i dosn't understand this! Do you have an example for me? – wolli911 Feb 05 '17 at 18:17

0 Answers0