如果iCloud打开(链接到与coreData同步)应用程序崩溃 [英] App Crash if iCloud is on (linked to sync with coreData)

查看:128
本文介绍了如果iCloud打开(链接到与coreData同步)应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在存储类的init使用的代码,它工作正常,直到最近..当我尝试测试,它崩溃(标记如下)在addPersistentStoreWithType ...我注意到这切换到iPhone 5后,试图运行应用程序...但如果我关闭icloud在我的手机或测试它在模拟器上没有问题... ...

This is the code i used in the init for storage class and it worked fine until recently.. when i tried testing it, it crashes (marked below) at addPersistentStoreWithType ... i noticed this after switching to the iPhone 5 and was trying to run the app... but if i turn off icloud on my phone or test it on the simulator there are no problems...

-(id)init
{
    self = [super init];
    if(self)
    {
        NSLog(@"%s", __FUNCTION__);
        favColors = [[NSMutableArray alloc] init];
        model = [NSManagedObjectModel mergedModelFromBundles:nil];
        NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
        NSString *path = [self itemArchivePath];
        NSURL *storeURL = [NSURL fileURLWithPath:path];
        NSError *error = nil;
        NSMutableDictionary *options = [NSMutableDictionary dictionary];

        NSURL *ubiq = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
        if (ubiq) {
            NSLog(@"iCloud access at %@", ubiq);
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(contentChange:) name:NSPersistentStoreDidImportUbiquitousContentChangesNotification object:nil];
            NSFileManager *fm = [NSFileManager defaultManager];
            NSURL *ubcontainer = [fm URLForUbiquityContainerIdentifier:nil];
            [options setObject:@"color" forKey:NSPersistentStoreUbiquitousContentNameKey];
            [options setObject:ubcontainer forKey:NSPersistentStoreUbiquitousContentURLKey];

        } else {
            NSLog(@"No iCloud access");
        }
   // ************ Crash here **************
        if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:(ubiq?options:nil) error:&error]) {
            [NSException raise:@"Open failed" format:@"Reason: %@", [error localizedDescription]];
        }
        context = [[NSManagedObjectContext alloc] init];
        [context setPersistentStoreCoordinator:psc];
        [context setUndoManager:nil];

        [self loadAllItems];
    }
    return self;
}

- (NSString *)itemArchivePath
{
    NSArray *documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [documentDirectories objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"store.data"];
}

此外,如果我运行应用程序一次,关闭icloud后崩溃和运行应用程序再次..从icloud ...检索数据,并在应用程序上显示。

Also if i run the app once and turn off icloud after the crash and run the app again.. the data is retrieved from icloud... and shows on app.

输出日志显示此内容。


iCloud存取档案:// localhost / private / var / mobile / Library / Mobile%20Documents / xxx
-PFUbiquitySetupAssistant performPreStoreSetupWithError :: CoreData:Ubiquity:
基线文件存在,但无法读取

iCloud access at file://localhost/private/var/mobile/Library/Mobile%20Documents/xxx -PFUbiquitySetupAssistant performPreStoreSetupWithError:: CoreData: Ubiquity: The baseline file exists, but could not be read


推荐答案

这是一个内部iCloud错误。这不是你的错,并且没有什么你可以做的代码,将修复或防止它。它将随机发生,没有可预测的时间或原因的模式。遗憾的是,删除应用的数据是唯一真正的解决方案。这样做只会删除iCloud的数据副本,而不是存储在应用程序的Documents目录或其他非iCloud位置的数据,因此旧数据仍然存在并不奇怪。

That's an internal iCloud error. It's not your fault, and there's nothing you can do in code that would fix or prevent it. It will happen randomly, with no predictable pattern for when or why. Deleting data for the app is, unfortunately, the only real solution. Doing that only deletes iCloud's copy of the data, not data stored in your app's Documents directory or other non-iCloud locations, so it's not surprising that the old data would still be present.

这篇关于如果iCloud打开(链接到与coreData同步)应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆