Search code examples
iphoneios-simulatordevicefile-writing

.plist writing error on device


This snippet of code does work on the iPhone simulator but not on device, although I am looking for a file that has been written on disk in the documents directory

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath = [documentsDirectory stringByAppendingString:@"notificationScheduled.plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filepath];
if (fileExists) {
    NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:filepath];
    NSLog(@"%@", array);
    [array addObject:date];
    [array writeToFile:filepath atomically:YES];
} else {
    NSMutableArray *array = [NSMutableArray arrayWithObject:date];
    [array writeToFile:filepath atomically:YES];
}

Solution

  • Found the answer, instead of

    NSString *filepath = [documentsDirectory stringByAppendingString:@"notificationScheduled.plist"];
    

    Used

    NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"notificationScheduled.plist"];