【问题标题】:Update plist file in File Sharing folder - I really need advice更新文件共享文件夹中的 plist 文件 - 我真的需要建议
【发布时间】:2010-09-22 20:57:05
【问题描述】:

我需要打开一个位于文件共享文件夹中的 plist 文件,以便在每次启动应用程序时添加两条用户信息;就像在用户的新名称和电子邮件中一样(两者都是 NSString 类型,plist 文件是 Dictionary)。

然后需要再次将文件保存回文件共享文件夹,以便以后可以通过 iTunes 删除新更新的 plist 文件。

如果有人能帮忙,将不胜感激

【问题讨论】:

    标签: objective-c ipad plist itunes file-sharing


    【解决方案1】:

    可以在 Documents 目录中存储 plist。您将能够将 plist 加载到 NSMutableDictionary 中,修改字典并将其写回 Documents 目录。

    // get the path to the plist file
    NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
    NSString *documentsPath = [paths objectAtIndex:0]; 
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myfile.plist"];
    
    // read the plist into an NSMutableDictionary
    NSMutableDictionary *plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
    
    // make the additions to the plistDictionary
    
    // write the plist back to the documents directory
    [plistDictionary writeToFile:filePath atomically:YES];
    

    我不知道您是否可以通过 iTunes 删除 plist。

    【讨论】:

    • TomH 太棒了。效果很好。我在我的 -info.plist 文件中启用了文件共享,并且能够通过 iTunes 访问它。再次感谢。
    【解决方案2】:

    我发现的另一个很好的资源是“Humble Coder's”博客的一篇文章,位于以下位置。很好的建议和示例代码,因为我需要保存检索和更新我的 plist 文件。再次感谢那些提供帮助的人。

    http://humblecoder.blogspot.com/2010/03/revisited-storing-and-retrieving.html

    【讨论】:

      猜你喜欢
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多