UIDocument saveToUrl Delayed Crash - ios

I have a Core Data app that's been running fine for over 4 years. Last week I updated XCode to version 8.2.1 (can't remember what I was running before this, but it had been months since I updated it).
After updating, I'm now getting a crash that I can't track down. There's a delay between doing something in the app, and getting the crash to occur. I have attempted to setup global breakpoints to gain more information, but nothing specific is shown that I can tell.
I don't explicitly spawn any threads myself.
When my app first launches, in the viewDidLoad of my initial viewController I do this:
- (void)viewDidLoad
{
[super viewDidLoad];
NSFileManager* fileManager = [NSFileManager defaultManager];
NSURL* ubiquitousURL = [fileManager URLForUbiquityContainerIdentifier:nil];
NSDictionary* localOptions = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption,
nil];
NSURL* localURL = [fileManager URLForDirectory:NSDocumentDirectory
inDomain:NSUserDomainMask
appropriateForURL:nil
create:NO
error:nil];
NSURL* localCoreDataURL = [localURL URLByAppendingPathComponent:#"MyData"];
self.database = [[UIManagedDocument alloc] initWithFileURL:localCoreDataURL];
self.database.persistentStoreOptions = localOptions;
if( [fileManager fileExistsAtPath:[localCoreDataURL path]] )
{
[self.database openWithCompletionHandler: ^(BOOL success) {
//log statement
}];
}
else
{
NSFileCoordinator* coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateWritingItemAtURL:ubiquitousURL
options:NSFileCoordinatorWritingForDeleting
error:nil
byAccessor:^(NSURL *newURL) {
[[NSFileManager defaultManager] removeItemAtURL:newURL error:nil];
}];
[self.database saveToURL:localCoreDataURL
forSaveOperation:UIDocumentSaveForCreating
completionHandler:^(BOOL success) {
//log statement
}];
}
}
Later in the app, I allow the user to create some data and save it (create a new entity), like this:
NSManagedObjectContext* context = database.managedObjectContext;
NSError* error = nil;
if( ![context save:&error])
{
[AppUtility printNsError:error];
[NSException raise:NSInternalInconsistencyException format:#"An error occurred when saving context: %#",[error localizedDescription]];
}
else
{
if (![[context parentContext] save:&error])
{
NSLog(#"Error Saving Parent Data %#, %#", error, [error userInfo]);
}
}
The app will then run for 15 to 20 seconds, then suddenly crash. There is an error in the log that says
[NSError retain]: message sent to deallocated instance 0x608000443b10
And the output in the debug navigator looks like this:
Thread 1 Queue: com.apple.main-thread
0 __forwarding__
1 _forwarding_prep_0__
2 -[UIDocument saveToURL:forSaveOperation:completionHandler:
3 __55-[UIDocument _saveUnsavedChangesWithCompletionHandler:)_block_invoke_2
4 _dispatch_call_block_and_release
5 _dispatch_client_callout ()
6 _dispatch_main_queue_callback_4CF
7 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
8 __CFRunLoopRun
9 CFRunLoopRunSpecific
10 GSEventRunModal
11 UIApplicationMain
12 main
13 start
14 start
Enqueued from UIDocument File Access (Thread 5)
0 _dispatch_queue_push
1 __55-[UIDocument _saveUnsavedChangesWithCompletionHandler:]_block_invoke
2 _dispatch_call_block_and_release
...
Equeued from com.apple.main-thread (Thread 1)
0 _dispatch_queue_push
1 -[UIDocument _saveUnsavedChangesWithCompletionHandler:]
2 -[UIDocument _autosaveWithCompletionHandler:]
3 +[UIDocument _autosavingTimerDidFireSoContinue:]
4 __NSFireTimer ()
5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
...
In an attempt to get more information, I enabled Zombie settings, then ran this in XCode:
command script import lldb.macosx.heap
malloc_info --stack-history *memory address*
The output of that didn't seem to point to a specific line in my app:
(lldb) malloc_info --stack-history 0x60820f611fd0
0x000060820f611fd0: malloc( 48) -> 0x60820f611fd0
_NSZombie_NSError stack[0]: addr = 0x60820f611fd0, type=malloc, frames:
[0] 0x000000010ffcb130 libsystem_malloc.dylib`calloc + 30
[1] 0x000000010ea45458 libobjc.A.dylib`class_createInstance + 85
[2] 0x000000010ea4fd55 libobjc.A.dylib`_objc_rootAlloc + 42
[3] 0x000000010de1f19b Foundation`+[NSError errorWithDomain:code:userInfo:] + 37
[4] 0x000000010c1a4a3c CoreData`-[NSPropertyDescription(_NSInternalMethods) _nonPredicateValidateValue:forKey:inObject:error:] + 124
[5] 0x000000010c1a4bc0 CoreData`-[NSRelationshipDescription(_NSInternalMethods) _nonPredicateValidateValue:forKey:inObject:error:] + 80
[6] 0x000000010c1a3b40 CoreData`-[NSManagedObject(_NSInternalMethods) _validateValue:forProperty:andKey:withIndex:error:] + 384
[7] 0x000000010c1a3896 CoreData`-[NSManagedObject(_NSInternalMethods) _validatePropertiesWithError:] + 358
[8] 0x000000010c1a36f7 CoreData`-[NSManagedObject(_NSInternalMethods) _validateForSave:] + 119
[9] 0x000000010c1b3d4c CoreData`-[NSManagedObject validateForInsert:] + 76
[10] 0x000000010c1a2a77 CoreData`-[NSManagedObjectContext(_NSInternalAdditions) _validateObjects:forOperation:error:exhaustive:forSave:] + 1783
[11] 0x000000010c1a2202 CoreData`-[NSManagedObjectContext(_NSInternalAdditions) _validateChangesForSave:] + 146
[12] 0x000000010c1a1f56 CoreData`-[NSManagedObjectContext(_NSInternalChangeProcessing) _prepareForPushChanges:] + 214
[13] 0x000000010c19e972 CoreData`-[NSManagedObjectContext save:] + 562
[14] 0x000000010ce26a9d UIKit`__43-[UIManagedDocument contentsForType:error:]_block_invoke + 30
[15] 0x000000010c1b89a7 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 199
[16] 0x000000010c1b885f CoreData`-[NSManagedObjectContext performBlockAndWait:] + 255
[17] 0x000000010ce269f0 UIKit`-[UIManagedDocument contentsForType:error:] + 258
[18] 0x000000010cd9477c UIKit`-[UIDocument saveToURL:forSaveOperation:completionHandler:] + 486
[19] 0x000000010cd962b2 UIKit`__55-[UIDocument _saveUnsavedChangesWithCompletionHandler:]_block_invoke_2 + 156
[20] 0x000000010fd77978 libdispatch.dylib`_dispatch_call_block_and_release + 12
[21] 0x000000010fda10cd libdispatch.dylib`_dispatch_client_callout + 8
[22] 0x000000010fd818a4 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 406
[23] 0x000000010ef9de49 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
[24] 0x000000010ef6337d CoreFoundation`__CFRunLoopRun + 2205
[25] 0x000000010ef62884 CoreFoundation`CFRunLoopRunSpecific + 420
[26] 0x00000001115dfa6f GraphicsServices`GSEventRunModal + 161
[27] 0x000000010c5a1c68 UIKit`UIApplicationMain + 159
[28] 0x000000010bac23bf MyApp`main + 111 at main.m:16:9
[29] 0x000000010fded68d libdyld.dylib`start + 1
[30] 0x0000000110153001 libsystem_pthread.dylib`_thread + 1
Can someone help me diagnose this?

Related

Crash on calling addpersistentstorewithtype

I'm creating a NSPersistentStore with the code below, but it crashes with an error posted farther below.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
// Check if we need to copy initial database store
NSString *storePath = [[self applicationDocumentsDirectory]
stringByAppendingPathComponent: PersistentStoreFilename];
//[self checkPersistentStore:storePath];
NSURL *storeUrl = [NSURL fileURLWithPath:storePath];
// Enable automatic lightweight migration
NSDictionary *options = #{
NSMigratePersistentStoresAutomaticallyOption : #YES,
NSInferMappingModelAutomaticallyOption : #YES
};
NSError *error = nil;
NSDictionary *fileAttributes = [NSDictionary dictionaryWithObject:NSFileProtectionComplete forKey:NSFileProtectionKey];
NSLog(#"fileAttributes ---- %#",fileAttributes);
NSLog(#"before file attributes - storePath ---- %#",storePath);
[[NSFileManager defaultManager] setAttributes:fileAttributes ofItemAtPath:storePath error:&error];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[self managedObjectModel]];
NSLog(#"1.persistentStoreCoordinator ---- %#",persistentStoreCoordinator);
NSLog(#"2.applicationDocumentsDirectory ---- %#",[self applicationDocumentsDirectory]);
NSLog(#"3.PersistentStoreFilename ---- %#",PersistentStoreFilename);
NSLog(#"4.storePath ---- %#",storePath);
NSLog(#"4.storeUrl ---- %#",storeUrl);
NSLog(#"5)persistentStoreCoordinator ---- Error loading core data database");
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:options error:&error]) {
/*Error for store creation should be handled in here*/
// REA - removing current store and replacing with one from bundle
// NSFileManager *fileManager = [NSFileManager defaultManager];
// [fileManager removeItemAtPath:storePath error:nil];
// [self checkPersistentStore:storePath];
NSLog(#"First attempt addPersistentStoreWithType error %#, %#", error, [error userInfo]);
if(![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:storeUrl options:options error:&error]) {
// Even the bundle version isn't loading - something really bad happened and we can't run
NSLog(#"Second attempt addPersistentStoreWithType error %#, %#", error, [error userInfo]);
NSLog(#"6)persistentStoreCoordinator ---- Error loading core data database");
abort();
}
}
return persistentStoreCoordinator;
}
It causes a crash and below are the nslog from the device.
before file attributes - storePath ---- /var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite
1.persistentStoreCoordinator ----
2.applicationDocumentsDirectory ---- /var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents
3.PersistentStoreFilename ---- iPhoneCoreData.sqlite
4.storePath ---- /var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite
4.storeUrl ---- file:///var/mobile/Containers/Data/Application/AA4EF2AA-1E72-4BC9-A939-732A1BB65E71/Documents/iPhoneCoreData.sqlite
Crash Logs:
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
Termination Description: SPRINGBOARD, scene-create watchdog transgression: com.united.UnitedAgentMobileApp exhausted real (wall clock) time allowance of 19.27 seconds | | ProcessVisibility: Foreground | ProcessState: Running | WatchdogEvent: scene-create | WatchdogVisibility: Foreground | WatchdogCPUStatistics: ( | "Elapsed total CPU time (seconds): 21.220 (user 21.220, system 0.000), 53% CPU", | "Elapsed application CPU time (seconds): 19.319, 48% CPU" | )
Triggered by Thread: 0
Back Trace:
Thread 0 name: Dispatch queue: SQLQueue 0x117dc0080 for UnitediPhoneCoreData.sqlite
Thread 0 Crashed:
0 libcompression.dylib 0x00000001841865d8 zlibDecodeBufferSafe + 40
1 libcompression.dylib 0x000000018418747c zlib_decode_stream_process + 288
2 libcompression.dylib 0x000000018418747c zlib_decode_stream_process + 288
3 CoreData 0x000000018530d92c -[NSSQLiteConnection _decompressedModelWithData:] + 188
4 CoreData 0x000000018530dc5c -[NSSQLiteConnection fetchCachedModel] + 552
5 CoreData 0x00000001852e18b0 __34-[NSSQLCore cachedModelWithError:]_block_invoke + 112
6 CoreData 0x00000001852301d4 -[NSSQLStoreRequestContext executeRequestUsingConnection:] + 248
7 CoreData 0x00000001852b2118 __52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 84
8 libdispatch.dylib 0x000000018239aa14 _dispatch_client_callout + 16
9 libdispatch.dylib 0x00000001823a3618 _dispatch_queue_barrier_sync_invoke_and_complete + 56
10 CoreData 0x00000001852b2014 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 256
11 CoreData 0x00000001853a2524 -[NSSQLCoreDispatchManager routeStoreRequest:] + 264
12 CoreData 0x00000001852e3fdc -[NSSQLCore dispatchRequest:withRetries:] + 236
13 CoreData 0x00000001852e1738 -[NSSQLCore cachedModelWithError:] + 112
14 CoreData 0x00000001852e297c +[NSSQLCore cachedModelForPersistentStoreWithURL:options:error:] + 688
15 CoreData 0x00000001853363ac -[NSStoreMigrationPolicy sourceModelForStoreAtURL:metadata:error:] + 1256
16 CoreData 0x00000001853379c8 -[NSStoreMigrationPolicy+ 1653192 (InternalMethods) _gatherDataAndPerformMigration:] + 772
17 CoreData 0x00000001852bba34 __91-[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:]_block_invoke + 2896
18 CoreData 0x00000001852c956c gutsOfBlockToNSPersistentStoreCoordinatorPerform + 212
19 libdispatch.dylib 0x000000018239aa14 _dispatch_client_callout + 16
20 libdispatch.dylib 0x00000001823a3618 _dispatch_queue_barrier_sync_invoke_and_complete + 56
21 CoreData 0x00000001852b7944 _perform + 200
22 CoreData 0x00000001851adfa4 -[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:] + 384
So we followed the circuit breaker pattern and followed the below blog post to address the issue.
https://code.tutsplus.com/tutorials/core-data-from-scratch-migrations--cms-21844

iOS Crash Log NSObject doesNotRecognizeSelector: - at which line?

I have recorded a crash of my app, but the last line in my app (5 Control) points just to the method begin. How do I know in which line the problem is?
0 CoreFoundation 0x185f0af50 __exceptionPreprocess + 132
1 libobjc.A.dylib 0x1924141fc objc_exception_throw + 60
2 CoreFoundation 0x185f0fc04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 220
3 CoreFoundation 0x185f0d930 ___forwarding___ + 912
4 CoreFoundation 0x185e2d5dc _CF_forwarding_prep_0 + 92
5 Control 0x10005acb4 -[PaymillPaymentService handleTransactionListRequest:] (PaymillPaymentService.m:211)
6 Foundation 0x186a7416c __103+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke96 + 28
7 libdispatch.dylib 0x1929ec014 _dispatch_call_block_and_release + 24
8 libdispatch.dylib 0x1929ebfd4 _dispatch_client_callout + 16
9 libdispatch.dylib 0x1929f32b8 _dispatch_root_queue_drain + 556
10 libdispatch.dylib 0x1929f34fc _dispatch_worker_thread2 + 76
11 libsystem_pthread.dylib 0x192b816bc _pthread_wqthread + 356
12 libsystem_pthread.dylib 0x192b8154c start_wqthread + 4
Here the [lengthy] method code. I see a couple of places where I can add the check but how to I know it for sure that I fixed the issue? The problem is sporadical and I cannot reproduce it easily.
- (void)handleTransactionListRequest:(ServiceRequest *)serviceRequest
{
LRURLRequestOperation* operation = serviceRequest.operation;
NSHTTPURLResponse *response = (NSHTTPURLResponse *)operation.URLResponse;
if (response.statusCode == 200)
{
if (operation.responseData)
{
NSError *parserError = nil;
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:operation.responseData options:0 error:&parserError];
//NSLog(#"%#", data);
if (!parserError)
{
NSArray* transactions = [data objectForKey:#"data"];
if (0 == serviceRequest.currentOffset)
{
NSNumber* totalCountObj = [data objectForKey:#"data_count"];
serviceRequest.totalCount = [totalCountObj intValue];
}
int loadedCount = 0;
if (transactions)
{
for (id object in transactions)
{
TransactionInfo* info = [self createTransactionFrom:object];
[serviceRequest.transactionList addTransaction:info];
[info release];
loadedCount++;
}
}
if (loadedCount + serviceRequest.currentOffset >= serviceRequest.totalCount)
{
if ([serviceRequest.delegate respondsToSelector:#selector(transactionListLoadingComplete:)])
[serviceRequest.delegate transactionListLoadingComplete:serviceRequest];
serviceRequest.transactionList.timeStamp = [[NSDate date] timeIntervalSince1970];
NSLog(#"COMPLETE: %d transaction loaded ", serviceRequest.totalCount);
}
else
{
serviceRequest.currentOffset += loadedCount;
bool needToContinue = YES;
if ([serviceRequest.delegate respondsToSelector:#selector(transactionListLoadingContinue:)])
needToContinue = [serviceRequest.delegate transactionListLoadingContinue];
if (needToContinue)
{
[self continueRetrievingTransactionListFor:serviceRequest];
NSLog(#"CONTINUE: %d of %d loaded ", serviceRequest.currentOffset, serviceRequest.totalCount);
}
}
return; // all OK cases
}
}
}
if ([serviceRequest.delegate respondsToSelector:#selector(transactionListLoadingFailed:with:)])
[serviceRequest.delegate transactionListLoadingFailed:serviceRequest with:response.statusCode];
NSLog(#"ERROR: Loading Transactions Response Code: %ld", (long)response.statusCode);
}
Short Answer:
You are sending a message to an object that cannot validly respond to it. The stack trace is telling you that when you make the call [PaymillPaymentService handleTransactionListRequest:] that PaymillPaymentService cannot accept handleTransactionListRequest.
Long answer:
Look at the stack trace here:
5 Control 0x10005acb4 -[PaymillPaymentService handleTransactionListRequest:] (PaymillPaymentService.m:211)
This is telling you that in the file PaymillPaymentService.m on line 211 you are sending PaymillPaymentService the message handleTransactionListRequest to which it cannot validly respond. In your discussion with rmaddy, Hot Licks, and Paulc11 you mentioned that line 211 is the function entry for handleTransactionListRequest (in whatever file it resides). If that's the case it is coincidental.
If you want further follow up you need to post PaymillPaymentService.m and ensure that you include all the line numbers.

RestKit Paginator Crash: Cannot determine hasNextPage: paginator is not loaded

For some reason, I randomly sometimes get this crash.
Fatal Exception: NSInternalInconsistencyException
Cannot determine hasNextPage: paginator is not loaded.
Thread : Fatal Exception: NSInternalInconsistencyException
0 CoreFoundation 0x309a1f4b __exceptionPreprocess + 130
1 libobjc.A.dylib 0x3b1386af objc_exception_throw + 38
2 CoreFoundation 0x309a1e25 +[NSException raise:format:]
3 Foundation 0x31349fe3 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 90
4 Poka 0x004f0f71 -[RKPaginator hasNextPage] (RKPaginator.m:151)
5 Poka 0x00289a41 __66-[PokaLocationContentManagerSingleton fetchLatestPlantsWithCount:]_block_invoke (PokaLocationContentManagerSingleton.m:345)
6 Poka 0x004f2495 __24-[RKPaginator loadPage:]_block_invoke157 (RKPaginator.m:231)
7 Poka 0x004e9355 __66-[RKObjectRequestOperation setCompletionBlockWithSuccess:failure:]_block_invoke244 (RKObjectRequestOperation.m:477)
8 libdispatch.dylib 0x3b61bd1b _dispatch_call_block_and_release + 10
9 libdispatch.dylib 0x3b61bd07 _dispatch_client_callout + 22
10 libdispatch.dylib 0x3b62278d _dispatch_main_queue_callback_4CF$VARIANT$mp + 268
11 CoreFoundation 0x3096c819 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
12 CoreFoundation 0x3096b0ed __CFRunLoopRun + 1300
13 CoreFoundation 0x308d5c27 CFRunLoopRunSpecific + 522
14 CoreFoundation 0x308d5a0b CFRunLoopRunInMode + 106
15 GraphicsServices 0x355c9283 GSEventRunModal + 138
16 UIKit 0x33179049 UIApplicationMain + 1136
17 Poka 0x0006df95 main (main.m:17)
18 libdyld.dylib 0x3b640ab7 start + 2
I am loading the Paginator like this:
- (void)fetchLatestPlantsWithCount:(NSNumber *)count
{
RKObjectManager *objectManager = [RKObjectManager sharedManager];
NSString *requestString = [NSString stringWithFormat:#"/api/rest/plants/?count=%#&limit=:perPage&offset=:offset", count];
NSDictionary *parameters = nil;
if(_dateFilterLastModifiedAppend)
parameters = [[NSDictionary alloc]initWithObjectsAndKeys:_dateFilterLastModifiedAppend, #"last_modified_date__gte", nil];
RKPaginator *paginator = [objectManager paginatorWithPathPattern:requestString parameters:parameters];
paginator.perPage = API_PER_PAGE_LIMIT;
[ZAActivityBar showWithStatus:[NSString stringWithFormat:NSLocalizedStringFromTable(#"Downloading latest plants: %# remaining", #"PokaLocalizable", nil), count]];
[paginator setCompletionBlockWithSuccess:^(RKPaginator *paginator, NSArray *objects, NSUInteger page) {
if([paginator hasNextPage])
{
[ZAActivityBar showWithStatus:[NSString stringWithFormat:NSLocalizedStringFromTable(#"Downloading latest plants: %# remaining", #"PokaLocalizable", nil), [NSNumber numberWithInt:([count integerValue] - paginator.offset)]]];
[paginator loadNextPage];
}
else
{
[self fetchLatestProductionLinesCount];
}
} failure:^(RKPaginator *paginator, NSError *error) {
[self fetchLatestProductionLinesCount];
}];
[paginator loadPage:1];
}
Finally, I added some code to RestKit in order to load the paginator. I don't think it is the problem though.
- (RKPaginator *)paginatorWithPathPattern:(NSString *)pathPattern parameters:(NSDictionary *)parameters
{
NSAssert(self.paginationMapping, #"Cannot instantiate a paginator when `paginationMapping` is nil.");
NSMutableURLRequest *request = [self requestWithMethod:#"GET" path:pathPattern parameters:parameters];
RKPaginator *paginator = [[RKPaginator alloc] initWithRequest:request paginationMapping:self.paginationMapping responseDescriptors:self.responseDescriptors];
#ifdef _COREDATADEFINES_H
paginator.managedObjectContext = self.managedObjectStore.mainQueueManagedObjectContext;
paginator.managedObjectCache = self.managedObjectStore.managedObjectCache;
paginator.fetchRequestBlocks = self.fetchRequestBlocks;
#endif
paginator.operationQueue = self.operationQueue;
Class HTTPOperationClass = [self requestOperationClassForRequest:request fromRegisteredClasses:self.registeredHTTPRequestOperationClasses];
if (HTTPOperationClass) [paginator setHTTPOperationClass:HTTPOperationClass];
return paginator;
}
The only difference is that I pass some parameters to it.
The thing I don't understand is that I load other objects, WITH that same code with the only difference being the type of objects I am downloading. I execute almost that same code right before executing this one, and it works perfectly fine. Hence, my question as to I am confused...
Some more information:
It says the object count is 1, that page is 1, but apparently it is not loaded?
Note that I call the paginator multiple times within the same page. I do the paginator for one type of objects... once it is done I do it for another one... and so on.
All pull requests that I mentioned before were merged already to master. So just use the newest version.
I found an issue and fixed it if you are interested. I posted Pull Request on RestKit github page
https://github.com/RestKit/RestKit/pull/2156
I would recommend to use my fork on branch inventorum where I also cherry picked malloc error fix:
https://github.com/bimusiek/RestKit/commits/inventorum

SIGABRT crash because of SDWebImageCache

I am getting this crash log (getting it from users, cannot reproduce it):
Threads
_________________________________
Thread: Unknown Name (Crashed)
0 libsystem_kernel.dylib 0x382dd1fc __pthread_kill + 8
1 libsystem_c.dylib 0x3828dffd abort + 77
2 libc++abi.dylib 0x375bccd7 abort_message + 75
3 libc++abi.dylib 0x375d320d _ZSt11__terminatePFvvE + 149
4 libc++abi.dylib 0x375d2d2d __cxa_increment_exception_refcount + 1
5 libobjc.A.dylib 0x37d1e7f7 objc_exception_rethrow + 43
6 CoreFoundation 0x2d811c9d CFRunLoopRunSpecific + 641
7 CoreFoundation 0x2d811a0b CFRunLoopRunInMode + 107
8 GraphicsServices 0x32538283 GSEventRunModal + 139
9 UIKit 0x300b5049 UIApplicationMain + 1137
10 Paok FC 0x000c6723 main (main.m:12)
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382ca83c kevent64 + 24
1 libdispatch.dylib 0x3820af9b _dispatch_mgr_thread$VARIANT$mp + 39
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382ddc7c __workq_kernreturn + 8
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382caadc semaphore_wait_trap + 8
1 libdispatch.dylib 0x38207a17 _dispatch_barrier_sync_f_slow + 139
2 Paok FC 0x0010c369 __42-[SDImageCache queryDiskCacheForKey:done:]_block_invoke (SDImageCache.m:308)
3 libdispatch.dylib 0x38201d1b _dispatch_call_block_and_release + 11
4 libdispatch.dylib 0x38208273 _dispatch_queue_drain$VARIANT$mp + 375
5 libdispatch.dylib 0x3820806b _dispatch_queue_invoke$VARIANT$mp + 43
6 libdispatch.dylib 0x38208ce1 _dispatch_root_queue_drain + 77
7 libdispatch.dylib 0x38208f59 _dispatch_worker_thread2 + 57
8 libsystem_pthread.dylib 0x38343dbf _pthread_wqthread + 299
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382caa8c mach_msg_trap + 20
1 CoreFoundation 0x2d8a87c3 __CFRunLoopServiceMachPort + 155
2 CoreFoundation 0x2d8a6ee9 __CFRunLoopRun + 785
3 CoreFoundation 0x2d811c27 CFRunLoopRunSpecific + 523
4 CoreFoundation 0x2d811a0b CFRunLoopRunInMode + 107
5 Foundation 0x2e24c2f7 +[NSURLConnection(Loader) _resourceLoadLoop:] + 319
6 Foundation 0x2e2c1c87 __NSThread__main__ + 1063
7 libsystem_pthread.dylib 0x38345c1d _pthread_body + 141
8 libsystem_pthread.dylib 0x38345b8f _pthread_start + 103
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382dd440 __select + 20
1 libsystem_pthread.dylib 0x38345c1d _pthread_body + 141
2 libsystem_pthread.dylib 0x38345b8f _pthread_start + 103
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382ddc7c __workq_kernreturn + 8
Thread: Unknown Name
0 libsystem_kernel.dylib 0x382ddc7c __workq_kernreturn + 8
Crashed Registers
_________________________________
r12 0x148
r10 0x190
r11 0x1559ca80
cpsr 0x10
r4 0x6
r5 0x3a15318c
r6 0x0
r7 0x27d45a60
r0 0x0
r1 0x0
r2 0x0
r3 0x2060
sp 0x27d45a54
r8 0x1558f8e0
r9 0x1
pc 0x382dd1fc
lr 0x38346a33
The method crashing in SDWebImageCache.m is this:
- (NSOperation *)queryDiskCacheForKey:(NSString *)key done:(void (^)(UIImage *image, SDImageCacheType cacheType))doneBlock
{
NSOperation *operation = NSOperation.new;
if (!doneBlock) return nil;
if (!key)
{
doneBlock(nil, SDImageCacheTypeNone);
return nil;
}
// First check the in-memory cache...
UIImage *image = [self imageFromMemoryCacheForKey:key];
if (image)
{
doneBlock(image, SDImageCacheTypeMemory);
return nil;
}
dispatch_async(self.ioQueue, ^
{
if (operation.isCancelled)
{
return;
}
#autoreleasepool
{
UIImage *diskImage = [self diskImageForKey:key];
if (diskImage)
{
CGFloat cost = diskImage.size.height * diskImage.size.width * diskImage.scale;
[self.memCache setObject:diskImage forKey:key cost:cost];
}
dispatch_main_sync_safe(^
{
doneBlock(diskImage, SDImageCacheTypeDisk);
});
}
});
return operation;
}
Has anyone experience this crash? If yes, is there a way to fix this?
Line 308 where the crash occurs is this:
dispatch_main_sync_safe(^
{
doneBlock(diskImage, SDImageCacheTypeDisk);
});
This method is called in another class from this method:
- (id<SDWebImageOperation>)downloadWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedWithFinishedBlock)completedBlock
{
// Invoking this method without a completedBlock is pointless
NSParameterAssert(completedBlock);
// Very common mistake is to send the URL using NSString object instead of NSURL. For some strange reason, XCode won't
// throw any warning for this type mismatch. Here we failsafe this error by allowing URLs to be passed as NSString.
if ([url isKindOfClass:NSString.class])
{
url = [NSURL URLWithString:(NSString *)url];
}
// Prevents app crashing on argument type error like sending NSNull instead of NSURL
if (![url isKindOfClass:NSURL.class])
{
url = nil;
}
__block SDWebImageCombinedOperation *operation = SDWebImageCombinedOperation.new;
__weak SDWebImageCombinedOperation *weakOperation = operation;
BOOL isFailedUrl = NO;
#synchronized(self.failedURLs)
{
isFailedUrl = [self.failedURLs containsObject:url];
}
if (!url || (!(options & SDWebImageRetryFailed) && isFailedUrl))
{
dispatch_main_sync_safe(^
{
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil];
completedBlock(nil, error, SDImageCacheTypeNone, YES);
});
return operation;
}
#synchronized(self.runningOperations)
{
[self.runningOperations addObject:operation];
}
NSString *key = [self cacheKeyForURL:url];
operation.cacheOperation = [self.imageCache queryDiskCacheForKey:key done:^(UIImage *image, SDImageCacheType cacheType)
{
if (operation.isCancelled)
{
#synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
return;
}
if ((!image || options & SDWebImageRefreshCached) && (![self.delegate respondsToSelector:#selector(imageManager:shouldDownloadImageForURL:)] || [self.delegate imageManager:self shouldDownloadImageForURL:url]))
{
if (image && options & SDWebImageRefreshCached)
{
dispatch_main_sync_safe(^
{
// If image was found in the cache bug SDWebImageRefreshCached is provided, notify about the cached image
// AND try to re-download it in order to let a chance to NSURLCache to refresh it from server.
completedBlock(image, nil, cacheType, YES);
});
}
// download if no image or requested to refresh anyway, and download allowed by delegate
SDWebImageDownloaderOptions downloaderOptions = 0;
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
if (options & SDWebImageRefreshCached) downloaderOptions |= SDWebImageDownloaderUseNSURLCache;
if (options & SDWebImageContinueInBackground) downloaderOptions |= SDWebImageDownloaderContinueInBackground;
if (options & SDWebImageHandleCookies) downloaderOptions |= SDWebImageDownloaderHandleCookies;
if (image && options & SDWebImageRefreshCached)
{
// force progressive off if image already cached but forced refreshing
downloaderOptions &= ~SDWebImageDownloaderProgressiveDownload;
// ignore image read from NSURLCache if image if cached but force refreshing
downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse;
}
id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
if (weakOperation.isCancelled)
{
dispatch_main_sync_safe(^
{
completedBlock(nil, nil, SDImageCacheTypeNone, finished);
});
}
else if (error)
{
dispatch_main_sync_safe(^
{
completedBlock(nil, error, SDImageCacheTypeNone, finished);
});
if (error.code != NSURLErrorNotConnectedToInternet)
{
#synchronized(self.failedURLs)
{
[self.failedURLs addObject:url];
}
}
}
else
{
BOOL cacheOnDisk = !(options & SDWebImageCacheMemoryOnly);
if (options & SDWebImageRefreshCached && image && !downloadedImage)
{
// Image refresh hit the NSURLCache cache, do not call the completion block
}
// NOTE: We don't call transformDownloadedImage delegate method on animated images as most transformation code would mangle it
else if (downloadedImage && !downloadedImage.images && [self.delegate respondsToSelector:#selector(imageManager:transformDownloadedImage:withURL:)])
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
{
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
dispatch_main_sync_safe(^
{
completedBlock(transformedImage, nil, SDImageCacheTypeNone, finished);
});
if (transformedImage && finished)
{
NSData *dataToStore = [transformedImage isEqual:downloadedImage] ? data : nil;
[self.imageCache storeImage:transformedImage imageData:dataToStore forKey:key toDisk:cacheOnDisk];
}
});
}
else
{
dispatch_main_sync_safe(^
{
completedBlock(downloadedImage, nil, SDImageCacheTypeNone, finished);
});
if (downloadedImage && finished)
{
[self.imageCache storeImage:downloadedImage imageData:data forKey:key toDisk:cacheOnDisk];
}
}
}
if (finished)
{
#synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
}
}];
operation.cancelBlock = ^{[subOperation cancel];};
}
else if (image)
{
dispatch_main_sync_safe(^
{
completedBlock(image, nil, cacheType, YES);
});
#synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
}
else
{
// Image not in cache and download disallowed by delegate
dispatch_main_sync_safe(^
{
completedBlock(nil, nil, SDImageCacheTypeNone, YES);
});
#synchronized(self.runningOperations)
{
[self.runningOperations removeObject:operation];
}
}
}];
return operation;
}
As the report says, this is related to semaphores. I found the line in question you commented
enterdispatch_main_sync_safe(^ { doneBlock(diskImage, SDImageCacheTypeDisk); });
to be exactly the one that is reported causing deadlock on SDWebImage GitHub error report [1]. If I understand correctly, this issue is already fixed, newest patch commit is 2 hours ago.
Maybe you can get that in some future release, or if you can use git, there it is..
My source:
[1] https://github.com/rs/SDWebImage/issues/507

Air Printing crash on ipad

I am having a trouble with printing on ipad. My code prints the pdf file perfectly for the first time; but when I print my pdf file for the second time the app freezes and then crashes.
Below is my code:
NSData *myPdfData = [NSData dataWithContentsOfFile:pdfPath];
UIPrintInteractionController *controller = [UIPrintInteractionController sharedPrintController];
if (controller && [UIPrintInteractionController canPrintData:myPdfData]){
controller.delegate = delegate;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [pdfPath lastPathComponent];
printInfo.duplex = UIPrintInfoDuplexLongEdge;
controller.printInfo = printInfo;
controller.showsPageRange = YES;
controller.printingItem = myPdfData;
// We need a completion handler block for printing.
UIPrintInteractionCompletionHandler completionHandler = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
if(completed && error){
NSLog(#"FAILED! due to error in domain %# with error code %u", error.domain, error.code);
}
};
[controller presentFromRect:[sender frame] inView:senderView animated:YES completionHandler:completionHandler];
}else {
NSLog(#"Couldn't get shared UIPrintInteractionController!");
}
Below is my stack trace from the device:
D
ate/Time: 2011-03-17 20:48:02.523 -0700
OS Version: iPhone OS 4.3 (8F190)
Report Version: 104
Exception Type: 00000020
Exception Codes: 0x8badf00d
Highlighted Thread: 0
Application Specific Information:
Brighton failed to resume in time
Elapsed total CPU time (seconds): 2.310 (user 0.290, system 2.020), 23% CPU
Elapsed application CPU time (seconds): 0.000, 0% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x30bd2ab0 0x30bc2000 + 68272
1 PrintKit 0x313f2c1a 0x313df000 + 80922
2 PrintKit 0x313ee9ea 0x313df000 + 63978
3 PrintKit 0x313eea90 0x313df000 + 64144
4 PrintKit 0x313eeab4 0x313df000 + 64180
5 PrintKit 0x313e4f96 0x313df000 + 24470
6 PrintKit 0x313e266a 0x313df000 + 13930
7 UIKit 0x335e3656 0x33311000 + 2958934
8 UIKit 0x335e904c 0x33311000 + 2981964
9 UIKit 0x335e8bcc 0x33311000 + 2980812
10 UIKit 0x335e99fc 0x33311000 + 2984444
11 UIKit 0x3343460c 0x33311000 + 1193484
12 Foundation 0x30d306ce 0x30cab000 + 546510
13 CoreFoundation 0x31c43a40 0x31bce000 + 481856
14 CoreFoundation 0x31c45ec4 0x31bce000 + 491204
15 CoreFoundation 0x31c4683e 0x31bce000 + 493630
16 CoreFoundation 0x31bd6ebc 0x31bce000 + 36540
17 CoreFoundation 0x31bd6dc4 0x31bce000 + 36292
18 GraphicsServices 0x32dbf418 0x32dbb000 + 17432
19 GraphicsServices 0x32dbf4c4 0x32dbb000 + 17604
It would be really helpful if anyone could help me figure out the issue.
Thanks in advance!
The clue is in this: "Brighton failed to resume in time."
When printing is finished, control is returned to your app but you take too long to respond. iOS thinks that you've stopped responding to input and kills your app.

Resources