Hi Eskimo,
sorry for the late reply (it looks like I didn't get the email notification for this thread) and thanks!
I now have a different problem. I had solved this issue in the immediate days after requesting help on this topic by deallocating the persistent container instance in a processinfo closure:
- (void)dealloc {
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
[processInfo performExpiringActivityWithReason:@"dealloc-NSPersistentContainer" usingBlock:^(BOOL expired) {
_persistentContainer = nil;
}];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Now, in XCode 8.x this was working fine and I didn't get anymore this issue.
Unfortunately now in XCode 9 (just upgraded) I get an EXC_BAD_ACCESS crash using this tecnique:
Foundation`__46-[_NSActivityAssertion _fireExpirationHandler]_block_invoke_2:
0x104f9af69 <+0>: pushq %rbp
0x104f9af6a <+1>: movq %rsp, %rbp
0x104f9af6d <+4>: pushq %r14
0x104f9af6f <+6>: pushq %rbx
0x104f9af70 <+7>: subq $0x30, %rsp
0x104f9af74 <+11>: movq %rdi, %rbx
0x104f9af77 <+14>: movq 0x20(%rbx), %rdi
-> 0x104f9af7b <+18>: callq *0x10(%rdi)
0x104f9af7e <+21>: movq 0x20(%rbx), %rdi
0x104f9af82 <+25>: movq 0x177b1f(%rip), %rsi ; "release"
0x104f9af89 <+32>: movq 0xca888(%rip), %r14 ; (void *)0x0000000105397940: objc_msgSend
0x104f9af90 <+39>: callq *%r14
0x104f9af93 <+42>: movq 0x180bd6(%rip), %rdi ; (void *)0x000000010512c518: _NSActivityAssertion
0x104f9af9a <+49>: movq 0x17f25f(%rip), %rsi ; "_expiringAssertionManagementQueue"
0x104f9afa1 <+56>: callq *%r14
0x104f9afa4 <+59>: movq 0xca36d(%rip), %rcx ; (void *)0x000000010a5f5070: _NSConcreteStackBlock
0x104f9afab <+66>: leaq -0x38(%rbp), %rsi
0x104f9afaf <+70>: movq %rcx, (%rsi)
0x104f9afb2 <+73>: movl $0xc2000000, 0x8(%rsi) ; imm = 0xC2000000
0x104f9afb9 <+80>: movl $0x0, 0xc(%rsi)
0x104f9afc0 <+87>: leaq 0x28(%rip), %rcx ; __46-[_NSActivityAssertion _fireExpirationHandler]_block_invoke_3
0x104f9afc7 <+94>: movq %rcx, 0x10(%rsi)
0x104f9afcb <+98>: leaq 0xdfa76(%rip), %rcx ; __block_descriptor_tmp.100
0x104f9afd2 <+105>: movq %rcx, 0x18(%rsi)
0x104f9afd6 <+109>: movq 0x28(%rbx), %rcx
0x104f9afda <+113>: movq %rcx, 0x20(%rsi)
0x104f9afde <+117>: movq %rax, %rdi
0x104f9afe1 <+120>: callq 0x104fd1af0 ; symbol stub for: dispatch_async
0x104f9afe6 <+125>: addq $0x30, %rsp
0x104f9afea <+129>: popq %rbx
0x104f9afeb <+130>: popq %r14
0x104f9afed <+132>: popq %rbp
0x104f9afee <+133>: retq
In the console I get this weird message prior the crash:
SimplePlusOneTodayWidget[3756:500441] writeASTCData:926: *** _astcPreTwiddle set for non-IIO_HAS_ASTCTWIDDLER codepath
When removing the processinfo clause in the dealloc method, hence setting to nil the _peristentContainer normally, I won't get the crash but still that message in the console everytime the widget is not shown anymore in the notification center (widget extensions get deallocated aggressively by the system to save resources as you may know).
EDIT:
Not using anymore the processinfo closure to dealloc the persistent container, I've got again —randomly— the UIApplicationEndBackgroundTaskError excpetion:
UIKit`UIApplicationEndBackgroundTaskError:
-> 0x10be8c530 <+0>: pushq %rbp
0x10be8c531 <+1>: movq %rsp, %rbp
0x10be8c534 <+4>: movq %rdi, %rcx
0x10be8c537 <+7>: leaq 0x11778aa(%rip), %rdi ; @"Can't endBackgroundTask: no background task exists with identifier %lx, or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug."
0x10be8c53e <+14>: xorl %eax, %eax
0x10be8c540 <+16>: movq %rcx, %rsi
0x10be8c543 <+19>: callq 0x10ccbccd8 ; symbol stub for: NSLog
0x10be8c548 <+24>: popq %rbp
0x10be8c549 <+25>: retq
This happens, as I stated orignally, when the widget gets deallocated and after the NSSQLiteConnection recives the disconnect message during the deallocation the NSPersistentStoreCooridinator, which itself happens during the deallocation of the NSPersistentContainer instance in the widget