1

这段代码确实可以在 iPhone 模拟器上运行,但不能在设备上运行,尽管我正在寻找已写入磁盘文档目录中的文件

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];
}
4

2 回答 2

0

是的。保存属性列表:这可能会帮助你

如果不只是离开这个,因为它可以帮助别人

NSString * error;
NSData * data = [NSPropertyListSerialization dataFromPropertyList:yourPlist format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
[data writeToFile:pathToYourFile atomically:YES];

yourPlist必须是一种NSData, NSString, NSNumber, NSDate, NSArray, 或NSDictionary对象。

阅读您的财产清单。

NSString * error;
NSData * data = [NSData dataWithContentsOfFile:pathToYourFile];
yourPlist = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
于 2011-06-30T13:55:17.540 回答
0

找到了答案,而不是

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

用过的

NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"notificationScheduled.plist"];
于 2011-06-30T19:11:30.623 回答