ios – RestKit核心数据NSError dealloc崩溃

ios – RestKit核心数据NSError dealloc崩溃,第1张

概述试图找到我在生产版本中看到的问题的底部,并且FINALLY能够在测试时重现它.使用RestKit v0.23.1,当使用以下代码执行RKManagedObjectRequestOperation时(插入仪器时)我得到“一个Objective-C消息被发送到一个解除分配的’NSError’对象(僵尸)”并且每次有对象时应用程序崩溃响应 JSON – 如果响应类似于“objects =();”没有崩溃 试图找到我在生产版本中看到的问题的底部,并且FINALLY能够在测试时重现它.使用RestKit v0.23.1,当使用以下代码执行RKManagedobjectRequestoperation时(插入仪器时)我得到“一个Objective-C消息被发送到一个解除分配的’NSError’对象(僵尸)”并且每次有对象时应用程序崩溃响应 JSON – 如果响应类似于“objects =();”没有崩溃 – 所以我猜它在RestKit /核心数据映射或存储中的某个地方?

RKManagedobjectRequestoperation *objectRequestoperation = [_objectManager managedobjectRequestoperationWithRequest:request managedobjectContext:_objectManager.managedobjectStore.mainQueueManagedobjectContext success:^(RKObjectRequestoperation *operation,RKMapPingResult *mapPingResult) {        DDLogInfo(@"INSIDE SUCCESS BLOCK");    } failure:^(RKObjectRequestoperation *operation,NSError *error) {        DDLogInfo(@"INSIDE ERROR BLOCK");    }];    [objectRequestoperation setwillMapDeserializedResponseBlock:^ID(ID deserializedResponseBody) {        DDLogInfo(@"Response JsON: %@",deserializedResponseBody);        return deserializedResponseBody;    }];    objectRequestoperation.savestopersistentStore = YES;    [objectRequestoperation start];

原始JsON正确记录在setwillMapDeserializedResponseBlock中,但永远不会到达成功和错误块内的日志.这是我从crashlytics回来的堆栈跟踪:

Thread : Crashed: NSOperationQueue Serial Queue0  libobjc.A.dylib                0x37dd4626 objc_msgSend + 51  Foundation                     0x2df5802d -[NSError dealloc] + 602  libobjc.A.dylib                0x37dd9b6b objc_object::sIDetable_release(bool) + 1743  libobjc.A.dylib                0x37dda0d3 (anonymous namespace)::autoreleasePoolPage::pop(voID*) + 3584  CoreFoundation                 0x2d569501 _CFautoreleasePoolPop + 165  Foundation                     0x2df69999 -[__NSOperationInternal _start:] + 10646  Foundation                     0x2e00d745 __NSOQSchedule_f + 607  libdispatch.dylib              0x382b8cbd _dispatch_queue_drain + 4888  libdispatch.dylib              0x382b5c6f _dispatch_queue_invoke + 429  libdispatch.dylib              0x382b95f1 _dispatch_root_queue_drain + 7610 libdispatch.dylib              0x382b98dd _dispatch_worker_thread2 + 5611 libsystem_pthread.dylib        0x383e4c17 _pthread_wqthread + 298
解决方法 这不是RestKit的问题.我经常看到这个问题,实际上看起来过度释放实际上发生在Apple的代码中.当您尝试保存到Core Data存储并且失败时,会发生此问题.核心数据报告错误,但错误处理错误.

我有一些导致保存失败的场景,这就是我修复它们的方法:

由于Data Protection API,数据存储无法访问.

忙碌等待让你的应用无法启动如下:

while(![[UIApplication sharedApplication] isProtectedDataAvailable]) {        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]];   }

如果商店中的数据不敏感,请禁用保护,如下所示:

[_coordinator addPersistentStoreWithType:NSsqliteStoreType                               configuration:nil                                         URL:url            options:@{NSPersistentStorefileProtectionKey:NSfileProtectionNone}                                       error:&error];

重要的是,在您可以访问该文件之前,不要尝试保存.如果您可以重新构造代码,以防止在无法访问数据库时访问数据库,这也很好.您可以使用Data Protection API应用程序委托方法来触发该机制.

数据存储已损坏 – 这里最好的做法是删除存储并重新开始.这是直接使用sqlite库检测损坏的商店的好方法.

#import <sqlite3.h>    sqlite3 *dbConnection;    if (sqlite3_open([[url absoluteString] UTF8String],&dbConnection) != sqlITE_OK) {        NSLog(@"[sqlITE] Unable to open database!");    }    sqlite3_stmt *statement = nil;    sqlite3_prepare_v2(dbConnection,"PRAGMA quick_check;",-1,&statement,NulL);    Nsstring *result = nil;    while (sqlite3_step(statement) == sqlITE_ROW) {        for (int i=0; i<sqlite3_column_count(statement); i++) {            int colType = sqlite3_column_type(statement,i);            if (colType == sqlITE_TEXT) {                const unsigned char *col = sqlite3_column_text(statement,i);                result = [Nsstring stringWithFormat:@"%s",col];            } else {                NSLog(@"[sqlITE] UNKNowN DATATYPE");            }        }    }    sqlite3_close(dbConnection);

这将运行sqlite PRAGMA查询以执行完整性检查.我使用quick_check,但如果你愿意等待额外的时间,你也可以使用integrity_check.您可以使用[result isEqualToString:@“ok”]来判断事情是否正常

总结

以上是内存溢出为你收集整理的ios – RestKit核心数据NSError dealloc崩溃全部内容,希望文章能够帮你解决ios – RestKit核心数据NSError dealloc崩溃所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1041628.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存