Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:是否可以防止或修复损坏的核心数据存储?_Ios_Swift_Core Data_Crash_Corruption - Fatal编程技术网

iOS:是否可以防止或修复损坏的核心数据存储?

iOS:是否可以防止或修复损坏的核心数据存储?,ios,swift,core-data,crash,corruption,Ios,Swift,Core Data,Crash,Corruption,我正在Swift中构建一个摄像头应用程序,即将发布一个新版本。一些用户报告说,该应用程序在启动时崩溃,我在该应用程序中批量删除旧图片时也遇到了同样的问题 基本上,当商店协调员试图保存数据库时,它会崩溃。在我的例子中,所有正常操作(包括添加和浏览图片)都可以正常工作,但“对许多对象进行更大的更改”(删除一半图片或将存储迁移到新版本)会导致崩溃。这不是迁移本身,因为它可以处理未损坏的数据 我的假设是,在使用过程中,旧商店被损坏了——我只能猜测原因和方式。可能是因为应用程序有漏洞,或者可能是因为用户在

我正在Swift中构建一个摄像头应用程序,即将发布一个新版本。一些用户报告说,该应用程序在启动时崩溃,我在该应用程序中批量删除旧图片时也遇到了同样的问题

基本上,当商店协调员试图保存数据库时,它会崩溃。在我的例子中,所有正常操作(包括添加和浏览图片)都可以正常工作,但“对许多对象进行更大的更改”(删除一半图片或将存储迁移到新版本)会导致崩溃。这不是迁移本身,因为它可以处理未损坏的数据

我的假设是,在使用过程中,旧商店被损坏了——我只能猜测原因和方式。可能是因为应用程序有漏洞,或者可能是因为用户在错误的时间偷走了应用程序。该应用程序处理相当大的数据集,我很难在正确的时刻保存数据。太早会影响用户界面,太迟会影响所需信息(即来自gps的信息)还不存在,我可能会丢失这些信息或将未保存的数据堆积在内存中,当应用程序终止时,我无法足够快地保存这些数据

以下是启动新版本的stacktrace,它是由一个简单的存储迁移引起的:

Thread 0 name:  Dispatch queue: NSPersistentStoreCoordinator 0x17007db40
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x0000000186e72c14 write + 8
1   libcopyfile.dylib               0x0000000186ce0d7c copyfile_internal + 1492
2   libcopyfile.dylib               0x0000000186ce35d4 copyfile + 4580
3   Foundation                      0x0000000188983910 -[NSFilesystemItemCopyOperation _handleFTSEntry:] + 428
4   Foundation                      0x0000000188982eb0 -[NSDirectoryTraversalOperation main] + 272
5   Foundation                      0x00000001888e50a4 -[__NSOperationInternal _start:] + 620
6   Foundation                      0x000000018897f728 -[NSFileManager copyItemAtPath:toPath:options:error:] + 268
7   Foundation                      0x000000018897f928 -[NSFileManager copyItemAtURL:toURL:options:error:] + 416
8   CoreData                        0x000000018a2c6a90 +[NSSQLCore _replacePersistentStoreAtURL:destinationOptions:withPersistentStoreFromURL:sourceOptions:error:] + 768
9   CoreData                        0x000000018a2ad7f8 __182-[NSPersistentStoreCoordinator(_NSPersistentStoreCoordinatorPrivateMathods) _replacePersistentStoreAtURL:destinationOptions:withPersistentStoreFromURL:sourceOptions:storeType:error:]_block_invoke + 480
10  CoreData                        0x000000018a2af3d8 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 168
11  CoreData                        0x000000018a29e890 _perform + 220
12  CoreData                        0x000000018a2ad524 -[NSPersistentStoreCoordinator(_NSPersistentStoreCoordinatorPrivateMathods) _replacePersistentStoreAtURL:destinationOptions:withPersistentStoreFromURL:sourceOptions:storeType:error:] + 256
13  CoreData                        0x000000018a307d74 -[NSStoreMigrationPolicy(InternalMethods) _gatherDataAndPerformMigration:] + 2804
14  CoreData                        0x000000018a2a2f08 __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 4764
15  CoreData                        0x000000018a2af3d8 gutsOfBlockToNSPersistentStoreCoordinatorPerform + 168
16  libdispatch.dylib               0x0000000186d4a1bc _dispatch_client_callout + 16
17  libdispatch.dylib               0x0000000186d577f0 _dispatch_barrier_sync_f_invoke + 84
18  CoreData                        0x000000018a29e87c _perform + 200
19  CoreData                        0x000000018a1b0470 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 388
20  KameraPROD                      0x00000001000e1244 specialized DataController.(persistentStoreCoordinator.getter).(closure #1) (DataController.swift:36)
21  KameraPROD                      0x00000001000e47dc AppDelegate.init() -> AppDelegate (DataController.swift:48)
22  UIKit                           0x000000018e0005a4 _UIApplicationMainPreparations + 1880
23  UIKit                           0x000000018dddc500 UIApplicationMain + 156
24  KameraPROD                      0x000000010006e160 main (AppDelegate.swift:5)
25  libdyld.dylib                   0x0000000186d7d5b8 start + 4
iOS:10.3(14E5277a)
Xcode 8.3测试版4
硬件:iphone6s

这是堆栈跟踪第20行的代码:

lazy var managedObjectContext: NSManagedObjectContext = {
    let coordinator = self.persistentStoreCoordinator
    var managedObjectContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
    managedObjectContext.persistentStoreCoordinator = coordinator
    return managedObjectContext
}()
我正在寻找:

1) 避免此类腐败的策略和
2) 修复它的方法

感谢您的见解

Andreas

在创建persistentStoreCoordinator时,您是否使用了任何特殊选项,如NSSQLitePragmasOption:@{@“synchronous”:@“OFF”}?这可能会导致腐败。“我的假设是,旧商店在使用过程中被损坏了……”这是一个非常大的假设。汤姆,你能解释一下为什么你会这样说吗?到目前为止,约95%的用户使用该应用程序时没有出现任何问题,而且这些大的更改工作正常。其余的个案正如我所描述,;读取和追加工作完美无瑕,但大型更改失败。我不明白为什么这不符合数据库损坏的模式。你的论点是什么?乔恩,不,我们没有这样的选择。当然。我明白了。我知道这是一个假设,我知道这可能是错误的。至少我有一个理论,只要我不能收集更多的信息或想法,它就会一直如此。如果我有答案,我不会在这里发帖寻求帮助。你的评论不会以任何方式向主题添加更多信息,我认为他们是光顾的。在创建你的SturtSturtCeCuror(比如NSqLITeApple MaskOp选项:@ { @)同步“:”“off”}时,你是否使用了任何特殊选项?这可能会导致腐败。“我的假设是,旧商店在使用过程中被损坏了……”这是一个非常大的假设。汤姆,你能解释一下为什么你会这样说吗?到目前为止,约95%的用户使用该应用程序时没有出现任何问题,而且这些大的更改工作正常。其余的个案正如我所描述,;读取和追加工作完美无瑕,但大型更改失败。我不明白为什么这不符合数据库损坏的模式。你的论点是什么?乔恩,不,我们没有这样的选择。当然。我明白了。我知道这是一个假设,我知道这可能是错误的。至少我有一个理论,只要我不能收集更多的信息或想法,它就会一直如此。如果我有答案,我不会在这里发帖寻求帮助。你的评论并没有给话题增加更多的信息,我认为他们是在光顾。