当我的设备进入“spaz模式”时,这是在少数设备上反复打开和关闭应用程序的技术术语,会在内部抛出EXC_BAD_ACCESS异常.代码段:
- (voID)compareversionChanges:(NSFiLeversion *)version { if (![DataLoader iCloudPreferenceEnabled]) { NSLog(@"Ignoring iCloud changes (version comparison) based on user preference"); return; } NSLog(@"compareversionChanges"); dispatch_queue_t aQueue = dispatch_get_global_queue(disPATCH_QUEUE_PRIORITY_DEFAulT,0); dispatch_async(aQueue,^(voID) { NSError *readError = nil; NSfileCoordinator *coordinator = [[NSfileCoordinator alloc] initWithfilePresenter:(ID)self]; [coordinator coordinateReadingItemAtURL:[version URL] options:0 error:&readError byAccessor:^(NSURL *newURL) { DataContext *loadedContext = nil; NSData *data = [NSData dataWithContentsOfURL:newURL]; NSError *e = nil; loadedContext = [self convertXmlDataToContext:data error:&e]; if (e) { NSLog(@"Done loading,error: %@",e); [[DataLoader applicationDelegate] displayError:e]; loadedContext = nil; } if (!loadedContext) { return; } ID appDelegate = [DataLoader applicationDelegate]; DataContext *inMemoryContext = nil; if (appDelegate != nil && [appDelegate respondsToSelector:@selector(context)]) { inMemoryContext = [appDelegate performSelector:@selector(context)]; } if (inMemoryContext) { NSLog(@"Performing iCloud context synchronizating..."); DataContextSynchronizer *synchronizer = [[DataContextSynchronizer alloc] init]; ChangeSet *changes = [synchronizer compareLocalContext:inMemoryContext andRemoteContext:loadedContext]; if ([[changes changes] count] > 0) { [SelectionManager disable]; @synchronized(appDelegate) { NSLog(@"Applying synchronization changes..."); [synchronizer applyChangeSet:changes toDataContext:inMemoryContext]; NSLog(@"Synchronization changes applIEd"); } [SelectionManager enable]; if ([appDelegate respondsToSelector:@selector(setSkipRefreshSave:)]) { [appDelegate performSelector:@selector(setSkipRefreshSave:) withObject:[NSNumber numberWithBool:YES]]; } dispatch_queue_t mainQueue = dispatch_get_main_queue(); dispatch_async(mainQueue,^(voID) { [SelectionManager notifyListeners]; }); if ([appDelegate respondsToSelector:@selector(setSkipRefreshSave:)]) { [appDelegate performSelector:@selector(setSkipRefreshSave:) withObject:[NSNumber numberWithBool:NO]]; } [self save:[[DataLoader applicationDelegate] context]]; } else { NSLog(@"No sync changes applicable."); } NSError *coordinateWriteRemoveError = nil; [coordinator coordinateWritingItemAtURL:newURL options:NSfileCoordinatorWritingForDeleting error:&coordinateWriteRemoveError byAccessor:^(NSURL *theURL) { theURL = [theURL copy]; NSError *removeOtherVersionsError = nil; [NSFiLeversion removeOtherVersionsOfItemAtURL:theURL error:&removeOtherVersionsError]; if (removeOtherVersionsError) { NSLog(@"Error removing other versions: %@",removeOtherVersionsError); } }]; if (coordinateWriteRemoveError) { NSLog(@"Error occurred coordinating write for deletion of other file versions: %@",coordinateWriteRemoveError); } } }]; if (readError) { NSLog(@"Done loading (outsIDe block) error: %@",readError); } });}
我认为一点语法高亮可能会使这更容易检查:
Link to image of code snippet and failure stack in Xcode
错误实际上发生在第1404行,正如您从下面的屏幕截图中看到的那样,它在Apple代码区域中很深.
Link to image of debugger
在提交雷达之前,我想我会在这里查看是否有什么我做错了?第1402行的额外[… copy]只是一个快速检查,以确保我没有丢失对块提供的参数的引用,并将被删除.
编辑:一个重要的说明!我正在使用ARC.
编辑2:我注意到在打电话时:
[NSFiLeversion otherVersionsOfItemAtURL:theURL]
返回值为nil,表示(通过文档):
…or nil if there is no such file. The array does not contain the version object returned by the currentVersionOfItemAtURL: method.
因此,在调用removeOtherVersionsOfItemAtURL:之前检查此方法的返回值,可以缓解此问题.但我仍然觉得抛出EXC_BAD_ACCESS很奇怪,而不是正确处理它的方法.
解决方法 我注意到在打电话时:[NSFiLeversion otherVersionsOfItemAtURL:theURL]
在调用removeOtherVersionsOfItemAtURL:之前,返回值为nil,表示(通过文档):
Returns: An array of file version objects or nil if there is no such
file. The array does not contain the version object returned by the
currentVersionOfItemAtURL: method.
因此,可以缓解此问题.但我仍然觉得奇怪的是,removeOtherVersionsOfItemAtURL:抛出EXC_BAD_ACCESS,而不是简单地返回NO的方法,或者只是填充提供的NSError对象.
我将提交雷达,当我收到回复时会在这里更新.
总结以上是内存溢出为你收集整理的objective-c – NSFileVersion调用期间EXC_BAD_ACCESS调用removeOtherVersionsOfItemAtURL:内部协调写入块全部内容,希望文章能够帮你解决objective-c – NSFileVersion调用期间EXC_BAD_ACCESS调用removeOtherVersionsOfItemAtURL:内部协调写入块所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)