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、、、、、、またはオブジェクトの種類NSDataNSStringある必要があります。NSNumberNSDateNSArrayNSDictionary

あなたの財産リストを読むために。

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 に答える