我創建了NSDictionary(+ dictionaryWitContentsOfFile :),使用-setValue:ForKey更改某些值,然後在應用程序終止時將此字典寫回一個帶有-writeToFile:的文件。 一切工作很好,直到我打開其他用戶帳戶內的同一個程序。-writeToFile:自動:(NSDictionary)在某些用戶帳戶上不成功
有沒有人有預感可能會導致這個錯誤?
文檔只是說-writeToFile:自動:當某些值不足以滿足plist時,將返回NO。這絕對不是這裏的問題。 我現在可以說的是,當我處於我正在開發的帳戶時,該程序可以編寫該文件。在我的Mac上有另一個用戶帳戶,它不是管理員,那裏有--writeToFile:自動返回NO(我在控制檯中看到這個)。我做了該帳戶管理員,但程序仍然無法保存在那裏。
感謝您的幫助,
沃爾夫岡
PS:我覺得我不能給你這不是多餘的更多信息。如果你想要更多的在你的手中,這裏是代碼:
- (void)awakeFromNib
{
NSString *path = [NSString stringWithFormat:@"%@/%@.plist",[[NSBundle mainBundle] resourcePath],NSUserName()];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(@"create new plist");
path = [[NSBundle mainBundle] pathForResource:@"DefaultAppData" ofType:@"plist"];
}
NSLog(@"open path:%@", path);
myPlist = [NSDictionary dictionaryWithContentsOfFile:path];
}
-(void)changeSomething
{
[myPlist setValue:[NSNumber numberWithBool:NO]] forKey:@"aKey"];
}
-(void)applicationWillTerminate:(NSNotification*)notification
{
NSLog(@"dict: %@",myPlist);
NSString *path = [NSString stringWithFormat:@"%@/%@.plist",[[NSBundle mainBundle] resourcePath],NSUserName()];
NSLog(@"save at path:%@ successful:%d", path, [myPlist writeToFile:path atomically:YES]);
}