.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
NS开发者_运维问答String *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];
}
Yes. To save a property list: this may help u
if not just leave this ,since it may help others
NSString * error;
NSData * data = [NSPropertyListSerialization dataFromPropertyList:yourPlist format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
[data writeToFile:pathToYourFile atomically:YES];
yourPlist
must be a kind of NSData
, NSString
, NSNumber
, NSDate
, NSArray
, or NSDictionary
object.
To read your property list.
NSString * error;
NSData * data = [NSData dataWithContentsOfFile:pathToYourFile];
yourPlist = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
Found the answer, instead of
NSString *filepath = [documentsDirectory stringByAppendingString:@"notificationScheduled.plist"];
Used
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"notificationScheduled.plist"];
精彩评论