这段代码可以在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];
}
答案 0 :(得分: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];
答案 1 :(得分:0)
找到答案,而不是
NSString *filepath = [documentsDirectory stringByAppendingString:@"notificationScheduled.plist"];
使用
NSString *filepath = [documentsDirectory stringByAppendingPathComponent:@"notificationScheduled.plist"];