【问题标题】:Xcode 6 simulator renames ApplicationID (not DeviceID) for each runXcode 6 模拟器为每次运行重命名 ApplicationID(而不是 DeviceID)
【发布时间】:2014-11-22 14:14:21
【问题描述】:

我已经阅读了一堆关于每次运行模拟器时更改文档目录路径的线程,但讨论的是关于 DeviceID,我同意它不会改变。改变的是ApplicationID,至少使用我要找到的方法,我在下次运行时找不到它,所以我的sql db不存在。

这是我所看到的示例:

第一次运行: 文档目录:/Users/annewest/Library/Developer/CoreSimulator/Devices/9DE1C194-BFB1-47CA-9CA1-77FA89F43960/data/Containers/Data/Application/4EFF7925-BB9E-4D9F-BD8C-B5BF44361189/Documents

然后我在 Xcode 中停止应用程序并再次运行。现在我明白了

第二次运行: 文档目录:/Users/annewest/Library/Developer/CoreSimulator/Devices/9DE1C194-BFB1-47CA-9CA1-77FA89F43960/data/Containers/Data/Application/8409664B-8EF4-4318-A6D7-EB07E965F0F6/Documents

注意第一个随机字符串 DEviceID 是一样的,但是 ApplicationID 改变了。

这是我用来查找目录和文件路径并创建持久存储协调器的代码:

- (NSString *) documentsDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths lastObject];
    NSLog(@"Documents directory%@", documentsDirectory);
    return documentsDirectory;
}

- (NSString *) dataStorePath
{
    return [[self documentsDirectory] stringByAppendingPathComponent:@"DataStore.sqlite"];
}

- (NSPersistentStoreCoordinator *) persistentStoreCoordinator
{
    if (!_persistentStoreCoordinator) {
        NSURL *storeURL = [NSURL fileURLWithPath:[self dataStorePath]];
        _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel];

        NSError *error;
        if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
            NSLog(@"Error adding persistent store %@ %@", error, [error userInfo]);
            abort();
        }
    }
    return _persistentStoreCoordinator;
}

比我有更多知识的人可以帮忙解决这个问题吗?

谢谢

【问题讨论】:

    标签: ios-simulator ios8 xcode6 nsdocumentdirectory


    【解决方案1】:

    闲逛了一个小时后,我发现了以下内容:

    使用不同的 ApplicationID 即可;系统似乎只是重命名了目录,但内容保持不变。我被 Lyra 愚弄了,它找不到原始目录。

    【讨论】:

      猜你喜欢
      • 2014-10-03
      • 2014-11-19
      • 2021-10-19
      • 1970-01-01
      • 2017-03-24
      • 2015-05-30
      • 1970-01-01
      • 1970-01-01
      • 2015-08-14
      相关资源
      最近更新 更多