Can anyone help me diagnose this crash. It happens in the animation block on the layoutIfNeeded() function call. Full function and crash report attached.
It seems to be related to memory but I can't pin it down.
private func showWarningView() {
DispatchQueue.main.async { [weak self] in
guard let strongSelf = self else { return }
if let safeAreaHeight = strongSelf.superview?.safeAreaLayoutGuide.layoutFrame.size.height {
let visibleBannerHeight: CGFloat = strongSelf.isBannerVisible ? strongSelf.bannerHeight : 0
let newConstraintConstant = (safeAreaHeight - strongSelf.externalBottomOffset - visibleBannerHeight) - strongSelf.warningBannerHeight
strongSelf.addInternalBottomOffset(with: strongSelf.warningBannerHeight)
strongSelf.warningViewTopConstraint.constant = newConstraintConstant
}
strongSelf.isWarningViewVisible = true
let showWarningView = UIViewPropertyAnimator(duration: 0.25, curve: .easeIn, animations: {
self?.layoutIfNeeded() // <---- Crash Happens here
})
showWarningView.startAnimation()
}
}
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000010 Exception Codes: 0x0000000000000001, 0x0000000000000010 VM Region Info: 0x10 is not in any region. Bytes before following region: 4337303536
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 102860000-102864000 [ 16K] r-x/r-x SM=COW ... Exception Note: EXC_CORPSE_NOTIFY Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [265]
Triggered by Thread: 0
Kernel Triage:
VM - Compressor failed a blocking pager_get
Thread 0 name:
Thread 0 Crashed:
0 libobjc.A.dylib 0x00000001d5d22f40 objc_msgSend + 32
1 UIKitCore 0x00000001bf72d010 -[UIView(AdditionalLayoutSupport) _nsis_center:bounds:inEngine:forLayoutGuide:] + 112 (NSLayoutConstraint_UIKitAdditions.m:3513)
2 UIKitCore 0x00000001bf7455b0 -[UILayoutGuide _updateLayoutFrameInOwningView:fromEngine:] + 80 (UILayoutGuide.m:109)
3 UIKitCore 0x00000001bf6c8350 -[UIView(AdditionalLayoutSupport) _is_layout] + 320 (NSLayoutConstraint_UIKitAdditions.m:3173)
4 UIKitCore 0x00000001bf5b1a7c -[UIView _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 1028 (UIView.m:12933)
5 UIKitCore 0x00000001bf5a9fb4 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2592 (UIView.m:18426)
6 QuartzCore 0x00000001c0d20cd0 CA::Layer::layout_if_needed(CA::Transaction*) + 532 (CALayer.mm:10116)
7 UIKitCore 0x00000001bf60dd90 -[UIView(Hierarchy) layoutBelowIfNeeded] + 584 (UIView.m:12868)
8 ****** 0x0000000102eb59d4 closure #1 in closure #1 in BottomDrawView.showWarningView() + 52 (BottomDrawView.swift:410)
9 ****** 0x0000000102eb59d4 partial apply for closure #1 in closure #1 in BottomDrawView.showWarningView() + 68 (:0)
10 ****** 0x0000000102f33378 thunk for #escaping #callee_guaranteed () -> () + 20 (:0)
11 UIKitCore 0x00000001bf8ee77c -[UIViewPropertyAnimator _runAnimations] + 212 (UIViewPropertyAnimator.m:1912)
12 UIKitCore 0x00000001bf78c6a4 __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke_2 + 108 (UIViewPropertyAnimator.m:3279)
13 UIKitCore 0x00000001bf637fec __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke + 128 (UIViewPropertyAnimator.m:3267)
14 UIKitCore 0x00000001bfb6eba8 __49-[UIViewPropertyAnimator startAnimationAsPaused:]_block_invoke.1142 + 284 (UIViewPropertyAnimator.m:3276)
15 UIKitCore 0x00000001bf95fa20 -[UIViewPropertyAnimator _setupAnimationTracking:] + 132 (UIViewPropertyAnimator.m:3230)
16 UIKitCore 0x00000001bf4c146c -[UIViewPropertyAnimator startAnimationAsPaused:] + 1048 (UIViewPropertyAnimator.m:3334)
17 ****** 0x0000000102eb4868 closure #1 in BottomDrawView.showWarningView() + 460 (BottomDrawView.swift:412)
18 ****** 0x0000000102f33378 thunk for #escaping #callee_guaranteed () -> () + 20 (:0)
19 libdispatch.dylib 0x00000001bcca2e6c _dispatch_call_block_and_release + 32 (init.c:1517)
20 libdispatch.dylib 0x00000001bcca4a30 _dispatch_client_callout + 20 (object.m:560)
21 libdispatch.dylib 0x00000001bccb2f48 _dispatch_main_queue_drain + 928 (inline_internal.h:2622)
22 libdispatch.dylib 0x00000001bccb2b98 _dispatch_main_queue_callback_4CF + 44 (queue.c:7770)
23 CoreFoundation 0x00000001bcff5800 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16 (CFRunLoop.c:1795)
24 CoreFoundation 0x00000001bcfaf704 __CFRunLoopRun + 2532 (CFRunLoop.c:3144)
25 CoreFoundation 0x00000001bcfc2bc8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
26 GraphicsServices 0x00000001d90f6374 GSEventRunModal + 164 (GSEvent.c:2200)
27 UIKitCore 0x00000001bf932648 -[UIApplication _run] + 1100 (UIApplication.m:3511)
28 UIKitCore 0x00000001bf6b3d90 UIApplicationMain + 364 (UIApplication.m:5064)
29 ****** 0x0000000102864a08 main + 68 (AppDelegate.swift:22)
30 dyld 0x0000000104505ce4 start + 520 (dyldMain.cpp:879)
In my iOS project I use Brad Larson's GPUImage.
All works fine when I install my app using Xcode, but when I install the app via TestFlight the app crashes every time I go to the viewcontroller that uses GPUImage framework.
I tried different solution but nothing:
Question 1
Question 2
This is my crash log, please help me:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x000000011b0b0000
Exception Codes: 0x0000000000000001, 0x000000011b0b0000
VM Region Info: 0x11b0b0000 is not in any region. Bytes after previous region: 1 Bytes before following region: 1412317184
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
MALLOC_LARGE 11afa8000-11b0b0000 [ 1056K] rw-/rwx SM=PRV
---> GAP OF 0x542e4000 BYTES
Stack Guard 16f394000-16f398000 [ 16K] ---/rwx SM=NUL
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [18891]
Triggered by Thread: 6
Thread 6 name: Dispatch queue: com.sunsetlakesoftware.GPUImage.processingQueue
Thread 6 Crashed:
0 AGXMetalG14 0x1f32140e8 0x1f2d43000 + 5050600
1 AGXMetalG14 0x1f3126ec0 0x1f2d43000 + 4079296
2 AGXMetalG14 0x1f3126ec0 0x1f2d43000 + 4079296
3 AGXMetalG14 0x1f3126e48 0x1f2d43000 + 4079176
4 AppleMetalGLRenderer 0x1f1f58184 invocation function for block in GLDContextRec::modifyTexSubImage(GLDTextureRec*, int, int, int, int, int, int, int, int, unsigned int, unsigned int, void const*, int, GLDBufferRec*, unsigned int) + 112
5 AppleMetalGLRenderer 0x1f1f57c54 gldModifyTexSubImage + 1916
6 GLEngine 0x1beabb52c glTexImage2D_Exec + 1992
7 OpenGLES 0x1beb7bd68 glTexImage2D + 84
8 GPUImage 0x100de4978 closure #1 in PictureInput.init(image:smoothlyScaleOutput:orientation:) + 336
9 GPUImage 0x100e23844 specialized closure #1 in SerialDispatch.runOperationSynchronously(_:) + 212
10 GPUImage 0x100decf14 partial apply for thunk for #callee_guaranteed () -> () + 20
11 GPUImage 0x100decd78 thunk for #escaping #callee_guaranteed () -> () + 20
12 libdispatch.dylib 0x1802a3670 _dispatch_client_callout + 20
13 libdispatch.dylib 0x1802b28c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
14 GPUImage 0x100ded7d8 specialized SerialDispatch.runOperationSynchronously(_:) + 412
15 GPUImage 0x100de5348 specialized PictureInput.init(image:smoothlyScaleOutput:orientation:) + 1136
16 GPUImage 0x100de54ac specialized PictureInput.__allocating_init(imageName:smoothlyScaleOutput:orientation:) + 196
17 GPUImage 0x100de4770 PictureInput.__allocating_init(imageName:smoothlyScaleOutput:orientation:) + 24
18 MyApp 0x1009c4cbc closure #1 in closure #2 in EditorViewController.metodoImpostaImgDaAsset() + 516
19 MyApp 0x1009e0dcc thunk for #escaping #callee_guaranteed () -> () + 20
20 libdispatch.dylib 0x1802a3670 _dispatch_client_callout + 20
21 libdispatch.dylib 0x1802a6b44 _dispatch_continuation_pop + 504
22 libdispatch.dylib 0x1802b9c48 _dispatch_source_invoke + 1356
23 libdispatch.dylib 0x1802a6674 _dispatch_queue_override_invoke + 500
24 libdispatch.dylib 0x1802b4de0 _dispatch_root_queue_drain + 396
25 libdispatch.dylib 0x1802b5608 _dispatch_worker_thread2 + 164
26 libsystem_pthread.dylib 0x1f19af0b8 _pthread_wqthread + 228
27 libsystem_pthread.dylib 0x1f19aee94 start_wqthread + 8
According to appstore review my app crashes on a specific point. How ever i have tried it on a real device as well as all simulators and works completely fine with me. I was sent a crash log and have symbolicated it. Following is the out come :
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000104dc8750 ChatInnerVC.checkIfCurrentUserBlocked() (in Blatini) (ChatInnerVC.swift:523)
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [6106]
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 Blatini 0x0000000104dc8750 ChatInnerVC.checkIfCurrentUserBlocked() (in Blatini) (ChatInnerVC.swift:523)
1 Blatini 0x0000000104dc3aec ChatInnerVC.viewDidLoad() (in Blatini) (ChatInnerVC.swift:63)
2 Blatini 0x0000000104dc3c48 #objc ChatInnerVC.viewDidLoad() (in Blatini) (<compiler-generated>:0)
3 UIKitCore 0x00000001a44eb748 0x1a40ef000 + 4179784
4 UIKitCore 0x00000001a44f02fc 0x1a40ef000 + 4199164
5 UIKitCore 0x00000001a44f06e8 0x1a40ef000 + 4200168
6 UIKitCore 0x00000001a444c3a8 0x1a40ef000 + 3527592
7 UIKitCore 0x00000001a446087c 0x1a40ef000 + 3610748
8 UIKitCore 0x00000001a4461c1c 0x1a40ef000 + 3615772
9 UIKitCore 0x00000001a4444900 0x1a40ef000 + 3496192
10 UIKitCore 0x00000001a502f2bc 0x1a40ef000 + 15991484
11 QuartzCore 0x00000001a7680978 0x1a7529000 + 1407352
12 QuartzCore 0x00000001a7680db8 0x1a7529000 + 1408440
13 QuartzCore 0x00000001a769321c 0x1a7529000 + 1483292
14 QuartzCore 0x00000001a75d7e10 0x1a7529000 + 716304
15 QuartzCore 0x00000001a76028c4 0x1a7529000 + 891076
16 QuartzCore 0x00000001a76034b4 0x1a7529000 + 894132
17 CoreFoundation 0x00000001a09b011c 0x1a0904000 + 704796
18 CoreFoundation 0x00000001a09aae4c 0x1a0904000 + 683596
19 CoreFoundation 0x00000001a09ab2dc 0x1a0904000 + 684764
20 CoreFoundation 0x00000001a09aabc8 0x1a0904000 + 682952
21 GraphicsServices 0x00000001aad8c5cc 0x1aad89000 + 13772
22 UIKitCore 0x00000001a4b5d744 0x1a40ef000 + 10938180
23 Blatini 0x0000000104d24950 main (in Blatini) (AppDelegate.swift:23)
24 libdyld.dylib 0x00000001a0827384 0x1a0826000 + 4996
Following is the function on line 523 :
// MARK: Check if current user is blocked i.e your self
func checkIfCurrentUserBlocked(){
if clientID.isEmpty {
self.clientID = self.chatModObj.from_user_id!
}
//line 523
apiManager.checkIfCurrentUserIsBlocked(self.clientID as! String, user_to: self.resid as! String, success: { (result) in
if result == true {
self.whenIAmBlocked()
}else{
print("You are not blocked")
}
}) { (error) in
print("You are not Blocked")
}
Following is the function in call on line 63 under viewdidload :
//line 63
if self.clientName!.isEmpty{
print("---->", self.chatModObj.from_username)
self.clientName = self.chatModObj.from_username
}
I am unable to track the cause of crash since it works really fine with me and from where the app store is complaining crash line 63 self.clientName is never empty.
I'm building a watchOS app that needs to periodically request information from a companion iPhone app to refresh a complication.
To achieve this, I have a WKApplicationRefreshBackgroundTask that runs periodically. It uses sendMessage(_:replyHandler:errorHandler:) from WatchConnectivity to request the information from the iPhone app, process the reply, and update the complication.
This works reliably for many users most of the time, however, I’m seeing Apple Watch crashes in Xcode related to sendMessage(_:replyHandler:errorHandler:) and I worry this is leading to missed complication updates for users. Some users have been complaining about the complication not updating, so I'm trying to identify if there are issues outside of the regular limitations on how often a complication can refresh in watchOS.
Does anyone have any suggestions on how I can fix this issue? Or, do you have any suggestions for how I can better troubleshoot what's going wrong to cause the crash and figure out how to prevent it?
I've included a full example of one of the crashes at the bottom, along with the code that handles the background task and the code that handles sending and receiving values from the paired iPhone.
I’m never sending a message without a replyHandler, so while others have seen problems because the delegate method for a message without a handler was not implemented on iPhone, I don’t think that’s the issue here. To be safe I implemented the delegate method on iPhone as an empty method that does nothing.
UPDATE 30 January 2020: A friend suggested that maybe the issue is that the task is being marked complete by the 10 second timer while it's still in progress, causing a memory issue when something that's pending finishes, but wasn't sure what could be done about it. Maybe that's core to the issue here?
Here's my background refresh code from ExtensionDelegate:
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
for task in backgroundTasks {
switch task {
case let backgroundTask as WKApplicationRefreshBackgroundTask:
// set a timer in case it doesn't complete
// the maximum allowed is 15 seconds, and then it crashes, so schedule the new task and mark complete after 10
var timeoutTimer: Timer? = Timer.scheduledTimer(withTimeInterval: 10, repeats: false) { (timer) in
self.scheduleBackgroundRefresh()
backgroundTask.setTaskCompletedWithSnapshot(false)
}
// schedule the next refresh now in case the request crashes
scheduleBackgroundRefresh()
WatchConnectivityManager.shared.requestDataFromPhone()
ComplicationManager.shared.reloadComplication()
// as long as the expiration timer is valid, cancel the timer and set the task complete
// otherwise, we'll assume the timer has fired and the task has been marked complete already
// if it's marked complete again, that's a crash
if let timerValid = timeoutTimer?.isValid, timerValid == true {
timeoutTimer?.invalidate()
timeoutTimer = nil
backgroundTask.setTaskCompletedWithSnapshot(true)
}
default:
// make sure to complete unhandled task types
task.setTaskCompletedWithSnapshot(false)
}
}
}
private func scheduleBackgroundRefresh() {
let fiveMinutesFromNow: Date = Date(timeIntervalSinceNow: 5 * 60)
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: fiveMinutesFromNow,
userInfo: nil) { (error) in
if let error = error {
fatalError("\(error)")
}
}
}
And here is WatchConnectivityManager:
import Foundation
import WatchKit
import WatchConnectivity
class WatchConnectivityManager: NSObject {
static let shared = WatchConnectivityManager()
let session = WCSession.default
private let receivedMessageQueue: OperationQueue = {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = 1
return queue
}()
private func process(messageOrUserInfo: [String : Any]) {
receivedMessageQueue.addOperation {
if let recievedValue = messageOrUserInfo["ValueFromPhone"] as? Int {
DispatchQueue.main.async {
ViewModel.shared.valueFromPhone = recievedValue
}
}
}
}
func requestDataFromPhone() {
if session.activationState == .activated {
let message: [String : Any] = ["Request" : true]
let replyHandler: (([String : Any]) -> Void) = { reply in
self.process(messageOrUserInfo: reply)
}
let errorHandler: ((Error) -> Void) = { error in
}
if session.isReachable {
session.sendMessage(message,
replyHandler: replyHandler,
errorHandler: errorHandler)
}
// send a request to the iPhone as a UserInfo in case the message fails
session.transferUserInfo(message)
}
}
}
extension WatchConnectivityManager: WCSessionDelegate {
func session(_ session: WCSession,
activationDidCompleteWith activationState: WCSessionActivationState,
error: Error?) {
if activationState == .activated {
requestDataFromPhone()
}
}
func session(_ session: WCSession,
didReceiveUserInfo userInfo: [String : Any])
{
process(messageOrUserInfo: userInfo)
}
}
Example crash:
Hardware Model: Watch3,4
AppVariant: 1:Watch3,4:6
Code Type: ARM (Native)
Role: Non UI
Parent Process: launchd [1]
OS Version: Watch OS 6.1.1 (17S449)
Release Type: User
Baseband Version: n/a
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000004
VM Region Info: 0x4 is not in any region. Bytes before following region: 638972
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 0009c000-000ac000 [ 64K] r-x/r-x SM=COW ...x/App Name
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [377]
Triggered by Thread: 9
Thread 0 name:
Thread 0:
0 libsystem_kernel.dylib 0x4381f864 semaphore_wait_trap + 8
1 libdispatch.dylib 0x436dac26 _dispatch_sema4_wait + 12 (lock.c:139)
2 libdispatch.dylib 0x436db09a _dispatch_semaphore_wait_slow + 104 (semaphore.c:132)
3 FrontBoardServices 0x46de503e -[FBSSceneSnapshotRequestHandle performRequestForScene:] + 408 (FBSSceneSnapshotRequestHandle.m:67)
4 FrontBoardServices 0x46de96ac -[FBSSceneSnapshotAction snapshotRequest:performWithContext:] + 218 (FBSSceneSnapshotAction.m:168)
5 FrontBoardServices 0x46da4320 -[FBSSceneSnapshotRequest performSnapshotWithContext:] + 292 (FBSSceneSnapshotRequest.m:65)
6 UIKitCore 0x5ba6a000 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_3 + 168 (UIApplication.m:7655)
7 FrontBoardServices 0x46de9568 -[FBSSceneSnapshotAction _executeNextRequest] + 244 (FBSSceneSnapshotAction.m:135)
8 FrontBoardServices 0x46de91e0 -[FBSSceneSnapshotAction executeRequestsWithHandler:completionHandler:expirationHandler:] + 244 (FBSSceneSnapshotAction.m:87)
9 UIKitCore 0x5ba69f20 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke_2 + 238 (UIApplication.m:7650)
10 UIKitCore 0x5ba69696 -[UIApplication _beginSnapshotSessionForScene:withSnapshotBlock:] + 772 (UIApplication.m:7582)
11 UIKitCore 0x5ba69e16 __65-[UIApplication _performSnapshotsWithAction:forScene:completion:]_block_invoke + 112 (UIApplication.m:7648)
12 UIKitCore 0x5b2c1110 -[UIScene _enableOverrideSettingsForActions:] + 40 (UIScene.m:1206)
13 UIKitCore 0x5b2c1330 -[UIScene _performSystemSnapshotWithActions:] + 112 (UIScene.m:1230)
14 UIKitCore 0x5ba69b90 -[UIApplication _performSnapshotsWithAction:forScene:completion:] + 382 (UIApplication.m:7647)
15 UIKitCore 0x5be89586 __98-[_UISceneSnapshotBSActionsHandler _respondToActions:forFBSScene:inUIScene:fromTransitionCont... + 146 (_UISceneSnapshotBSActionsHandler.m:54)
16 UIKitCore 0x5ba68fd4 _runAfterCACommitDeferredBlocks + 274 (UIApplication.m:3038)
17 UIKitCore 0x5ba5b3da _cleanUpAfterCAFlushAndRunDeferredBlocks + 198 (UIApplication.m:3016)
18 UIKitCore 0x5ba82702 _afterCACommitHandler + 56 (UIApplication.m:3068)
19 CoreFoundation 0x43b63644 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 18 (CFRunLoop.c:1758)
20 CoreFoundation 0x43b5f43c __CFRunLoopDoObservers + 350 (CFRunLoop.c:1868)
21 CoreFoundation 0x43b5f956 __CFRunLoopRun + 1150 (CFRunLoop.c:2910)
22 CoreFoundation 0x43b5f23a CFRunLoopRunSpecific + 370 (CFRunLoop.c:3192)
23 GraphicsServices 0x46973cd0 GSEventRunModal + 96 (GSEvent.c:2246)
24 UIKitCore 0x5ba61580 UIApplicationMain + 1730 (UIApplication.m:4773)
25 libxpc.dylib 0x438fbcf0 _xpc_objc_main.cold.3 + 152
26 libxpc.dylib 0x438eca34 _xpc_objc_main + 184 (main.m:126)
27 libxpc.dylib 0x438ee934 xpc_main + 110 (init.c:1568)
28 Foundation 0x443f3156 -[NSXPCListener resume] + 172 (NSXPCListener.m:276)
29 PlugInKit 0x4b58b26c -[PKService run] + 384 (PKService.m:165)
30 WatchKit 0x52e9dafe WKExtensionMain + 62 (main.m:19)
31 libdyld.dylib 0x43715e82 start + 2
Thread 1 name:
Thread 1:
0 libsystem_kernel.dylib 0x4381f814 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x4381eece mach_msg + 42 (mach_msg.c:103)
2 CoreFoundation 0x43b63946 __CFRunLoopServiceMachPort + 152 (CFRunLoop.c:2575)
3 CoreFoundation 0x43b5f9de __CFRunLoopRun + 1286 (CFRunLoop.c:2931)
4 CoreFoundation 0x43b5f23a CFRunLoopRunSpecific + 370 (CFRunLoop.c:3192)
5 Foundation 0x443bf398 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 180 (NSRunLoop.m:374)
6 Foundation 0x443bf2b4 -[NSRunLoop(NSRunLoop) runUntilDate:] + 76 (NSRunLoop.m:421)
7 UIKitCore 0x5badf012 -[UIEventFetcher threadMain] + 140 (UIEventFetcher.m:637)
8 Foundation 0x444c1b60 __NSThread__start__ + 708 (NSThread.m:724)
9 libsystem_pthread.dylib 0x438ad1ac _pthread_start + 130 (pthread.c:896)
10 libsystem_pthread.dylib 0x438b3f28 thread_start + 20
Thread 2 name:
Thread 2:
0 libsystem_kernel.dylib 0x43836d04 __psynch_cvwait + 24
1 libsystem_pthread.dylib 0x438b02c2 _pthread_cond_wait + 496 (pthread_cond.c:591)
2 libsystem_pthread.dylib 0x438aca4a pthread_cond_wait + 38 (pthread_cancelable.c:558)
3 Foundation 0x444381f0 -[NSOperation waitUntilFinished] + 446 (NSOperation.m:737)
4 Foundation 0x444a5302 __NSOPERATIONQUEUE_IS_WAITING_ON_AN_OPERATION__ + 22 (NSOperation.m:2610)
5 Foundation 0x444222ee -[NSOperationQueue addOperations:waitUntilFinished:] + 128 (NSOperation.m:2618)
6 WatchConnectivity 0x53f9871e __47-[WCSession handleUserInfoResultWithPairingID:]_block_invoke.491 + 540 (WCSession.m:1440)
7 WatchConnectivity 0x53fa5608 -[WCFileStorage enumerateUserInfoResultsWithBlock:] + 1564 (WCFileStorage.m:505)
8 WatchConnectivity 0x53f984ca __47-[WCSession handleUserInfoResultWithPairingID:]_block_invoke_2 + 284 (WCSession.m:1430)
9 Foundation 0x444a4794 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 10 (NSOperation.m:1541)
10 Foundation 0x443d2f7a -[NSBlockOperation main] + 74 (NSOperation.m:1560)
11 Foundation 0x444a63e2 __NSOPERATION_IS_INVOKING_MAIN__ + 22 (NSOperation.m:2184)
12 Foundation 0x443d2b96 -[NSOperation start] + 578 (NSOperation.m:2201)
13 Foundation 0x444a6b7c __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 22 (NSOperation.m:2215)
14 Foundation 0x444a6798 __NSOQSchedule_f + 134 (NSOperation.m:2226)
15 libdispatch.dylib 0x436d9846 _dispatch_call_block_and_release + 10 (init.c:1408)
16 libdispatch.dylib 0x436da8b8 _dispatch_client_callout + 6 (object.m:495)
17 libdispatch.dylib 0x436dc6f8 _dispatch_continuation_pop + 330 (inline_internal.h:2484)
18 libdispatch.dylib 0x436dc08c _dispatch_async_redirect_invoke + 520 (queue.c:803)
19 libdispatch.dylib 0x436e6eac _dispatch_root_queue_drain + 540 (inline_internal.h:2525)
20 libdispatch.dylib 0x436e73e0 _dispatch_worker_thread2 + 98 (queue.c:6628)
21 libsystem_pthread.dylib 0x438aecd2 _pthread_wqthread + 158 (pthread.c:2364)
22 libsystem_pthread.dylib 0x438b3f10 start_wqthread + 20
Thread 3:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 4:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 5:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 6 name:
Thread 6:
0 libsystem_kernel.dylib 0x43838c6c kevent_qos + 24
1 libdispatch.dylib 0x436f2b74 _dispatch_kq_poll + 204 (event_kevent.c:736)
2 libdispatch.dylib 0x436f280a _dispatch_kq_drain + 96 (event_kevent.c:809)
3 libdispatch.dylib 0x436f2196 _dispatch_event_loop_poke + 162 (event_kevent.c:1918)
4 libdispatch.dylib 0x436e32b8 _dispatch_mgr_queue_push + 110 (queue.c:5857)
5 WatchConnectivity 0x53f9aa26 -[WCSession createAndStartTimerOnWorkQueueWithHandler:] + 150 (WCSession.m:1803)
6 WatchConnectivity 0x53f90790 -[WCSession onqueue_sendMessageData:replyHandler:errorHandler:dictionaryMessage:] + 382 (WCSession.m:674)
7 WatchConnectivity 0x53f901da __51-[WCSession sendMessage:replyHandler:errorHandler:]_block_invoke.256 + 190 (WCSession.m:630)
8 Foundation 0x444a4794 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 10 (NSOperation.m:1541)
9 Foundation 0x443d2f7a -[NSBlockOperation main] + 74 (NSOperation.m:1560)
10 Foundation 0x444a63e2 __NSOPERATION_IS_INVOKING_MAIN__ + 22 (NSOperation.m:2184)
11 Foundation 0x443d2b96 -[NSOperation start] + 578 (NSOperation.m:2201)
12 Foundation 0x444a6b7c __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 22 (NSOperation.m:2215)
13 Foundation 0x444a6798 __NSOQSchedule_f + 134 (NSOperation.m:2226)
14 libdispatch.dylib 0x436e4c02 _dispatch_block_async_invoke2 + 80 (queue.c:525)
15 libdispatch.dylib 0x436da8b8 _dispatch_client_callout + 6 (object.m:495)
16 libdispatch.dylib 0x436dc6f8 _dispatch_continuation_pop + 330 (inline_internal.h:2484)
17 libdispatch.dylib 0x436dc08c _dispatch_async_redirect_invoke + 520 (queue.c:803)
18 libdispatch.dylib 0x436e6eac _dispatch_root_queue_drain + 540 (inline_internal.h:2525)
19 libdispatch.dylib 0x436e73e0 _dispatch_worker_thread2 + 98 (queue.c:6628)
20 libsystem_pthread.dylib 0x438aecd2 _pthread_wqthread + 158 (pthread.c:2364)
21 libsystem_pthread.dylib 0x438b3f10 start_wqthread + 20
Thread 7:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 8:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 9 name:
Thread 9 Crashed:
0 libdispatch.dylib 0x436eacec dispatch_channel_cancel + 6 (source.c:1020)
1 WatchConnectivity 0x53f909c6 __81-[WCSession onqueue_sendMessageData:replyHandler:errorHandler:dictionaryMessage:]_block_invoke + 42 (WCSession.m:675)
2 libdispatch.dylib 0x436da8b8 _dispatch_client_callout + 6 (object.m:495)
3 libdispatch.dylib 0x436dc6f8 _dispatch_continuation_pop + 330 (inline_internal.h:2484)
4 libdispatch.dylib 0x436ea81e _dispatch_source_invoke + 1758 (source.c:568)
5 libdispatch.dylib 0x436e6eac _dispatch_root_queue_drain + 540 (inline_internal.h:2525)
6 libdispatch.dylib 0x436e73e0 _dispatch_worker_thread2 + 98 (queue.c:6628)
7 libsystem_pthread.dylib 0x438aecd2 _pthread_wqthread + 158 (pthread.c:2364)
8 libsystem_pthread.dylib 0x438b3f10 start_wqthread + 20
Thread 10:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 11:
0 libsystem_pthread.dylib 0x438b3efc start_wqthread + 0
Thread 9 crashed with ARM Thread State (32-bit):
r0: 0x00000000 r1: 0x80000000 r2: 0x00000001 r3: 0x7fffffff
r4: 0x16548f40 r5: 0x00000000 r6: 0x00000110 r7: 0x3f057e58
r8: 0x00000000 r9: 0x00000000 r10: 0x00000000 r11: 0x00401600
ip: 0x66e39628 sp: 0x3f057e30 lr: 0x53f909c7 pc: 0x436eacec
cpsr: 0x80000030
I assume your friend is right:
When you set your background task as complete, the system will suspend your app, see here.
And the system can purge suspended apps without warning, see here.
So if this happens, replyHandler or errorHandler cannot be called, and the app crashes.
You can therefore not rely on sendMessage to wake up the iOS app and to call replyHandler in time.
I suggest that you initialize the transfer of complication data on iOS. To do so regularly, you could use silent push notifications that wake up your iOS app, and send new complication data using transferCurrentComplicationUserInfo(_:)see here. This userInfo is received even if your watch app is not running, and the complication data can be updated as required.
EDIT:
While my solution above might work, there might be a much simpler solution:
Maybe it is not required to update your ViewModel in respond to sendMessage, only the complications. If so, you could simply use sendMessage with replyHandler and errorHandler set to nil.
sendMessage is guaranteed to wake up the iOS app in the future, even when the watchOS app is already inactive. The iOS app could then send complication data, and these would be displayed immediately.
Additionally, the iOS app could send the userInfo that updates your ViewModel as application context. It would then be available when the watchOS app becomes active again, and you can update the ViewModel.
If this fits to your use case, you could simply remove the timer and complete the background task immediately after sendMessage.
- (void)getFromWebwithCompletionBlock:(ResponseCallback)completionBlock
{
[/*
.... network call
*/
{
completionBlock();
}];
}
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000010
0 asd 0x1001dc2cc __69-[Engine getFromWebwithCompletionBlock:]_block_invoke (Engine.m:200)
1 asd 0x10010f4d8 -[NetworkCallService sendResponseForCall:] (NetworkCallService.m:422)
2 asd 0x10010f008 -[NetworkCallService respondSuccessWithData:responseData:] (NetworkCallService.m:396)
3 asd 0x10010e778 __43-[NetworkCallService connectWithRequest:]_block_invoke_2 (NetworkCallService.m:337)
4 libdispatch.dylib 0x193f39994 _dispatch_call_block_and_release + 24
5 libdispatch.dylib 0x193f39954 _dispatch_client_callout + 16
6 libdispatch.dylib 0x193f3e20c _dispatch_main_queue_callback_4CF + 1608
7 CoreFoundation 0x1820cb7f8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
8 CoreFoundation 0x1820c98a0 __CFRunLoopRun + 1492
9 CoreFoundation 0x181ff52d4 CFRunLoopRunSpecific + 396
10 GraphicsServices 0x18b8136fc GSEventRunModal + 168
11 UIKit 0x186bbafac UIApplicationMain + 1488
12 Mobikwik 0x1000c8fcc main (main.m:16)
13 libdyld.dylib 0x193f66a08 start + 4
as far as i got from other stackoverflow posts my completionBlock is getting released before execution. My doubt here is if i am passing my completionBlock as an argument to the function, How can it be deallocated?
Isn’t my function’s class retaining the block? I am currently going to fix it by checking if completionBlock is nil, but i would like to know how can it ever be nil