ios - 使用GROUP APP在两个目标中共享文件

标签 ios iphone xcode nsfilemanager ios8

- (void) readTheFile{

    NSError *error;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *path = [self getTheFilePath];

    if (![fileManager fileExistsAtPath: path])
    {
        NSString *bundle = [[NSBundle mainBundle] pathForResource:@"setting" ofType:@"plist"];

        [fileManager copyItemAtPath:bundle toPath: path error:&error];
    }
}

- (NSString *)getTheFilePath{

    NSURL *url =  [[NSFileManager defaultManager]     containerURLForSecurityApplicationGroupIdentifier:@"com.group.test"];
    NSString *path = [url.absoluteString stringByAppendingPathComponent:@"setting.plist"]; 
    path = [path stringByReplacingOccurrencesOfString:@"file:" withString:@""];
    return path;
}

大家好,我遇到了一个混乱的问题。
我在一个项目中有两个目标,一个是扩展目标。
所以我想在两个目标中共享一些plist文件。因此,我成功地在两个目标中创建了功能组App。
我的想法是我在一个目标中创建了plist文件,其他扩展应用程序需要检查相同的位置(上述代码),并检查文件是否存在。如果不存在,请创建新的plist文件。
我在模拟器上测试一切正常。
但是当我在设备上运行时,所有奇怪的东西都会出来。
当我读取文件时,getTheFilePath提供正确的路径,但是当我检查文件是否存在时。显示NO。
但是实际上我已经从第一个目标创建了文件。
因此,程序继续运行,并从Bundle复制文件并粘贴到路径中。
但是我得到有关文件已存在的错误。
Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" 
"The operation couldn’t be completed. File exists"  

有时它会自动重新启动设备。为什么?

请帮助我,我正在使用xCode 6 beta,并在iOS8 iPhone5s上进行了测试

最佳答案

我最近一直在研究应用程序组,尤其是在即将推出iOS 8的情况下,现在已经多次遇到此问题。事实证明,这是当前Xcode Beta中的错误。我敢肯定,您现在已经知道了这一点,但是对于尚未更新但仍然存在相同问题的任何人,都应该可以解决。

关于ios - 使用GROUP APP在两个目标中共享文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24281870/

相关文章:

ios - Xcode 7.1 : Simulator can't be opened because the identity of developer cannot be confirmed

ios - UICollectionView.backgroundView 损坏

iphone - 设置导航栏标题的对齐方式

iphone - 是否 applicationDidFinishLaunching : get called when application is updated and launched first time?

iphone - Xcode 4 自动完成错误

ios - 设备崩溃,但调试器无话可说

iphone - UITabBar全透明

android - 我可以强制用户在 Android 和 iOS 中升级我的应用程序吗?

ios - 在 iOS11 中更改 UISearchBar 背景图片

iphone - ShareKit API 变更