I am receiving this error from a bug report and have no idea what has caused it.
Here is the complete error message:
Hardware Model: [object Object]
Process: SkippersLog
Identifier: de.sioned.skipperslog
Version: 1.2.1
OS Version: iOS 13.6.1
NSInvalidArgumentException: -[__NSCFNumber count]: unrecognized selector sent to instance 0x8000000000000000
0 CoreFoundation ___exceptionPreprocess
1 libobjc.A.dylib _objc_exception_throw
2 CoreFoundation -[NSObject(NSObject) doesNotRecognizeSelector:]
3 CoreFoundation ____forwarding___
4 CoreFoundation ___forwarding_prep_0___
5 SkippersLog generic specialization <__C.CKRecordID, __C.CKRecord> of Swift.Dictionary._Variant.updateValue(_: __owned B, forKey: A) -> B? (<compiler-generated>)
6 SkippersLog updateValue (<compiler-generated>)
7 SkippersLog closure #1 () -> () in SkippersLog.CloudKitFactory.transferAllTablesToCloud() -> () (CloudKitFactory.swift:203:18)
8 SkippersLog reabstraction thunk helper from #escaping #callee_guaranteed () -> () to #escaping #callee_unowned #convention(block) () -> () (<compiler-generated>)
9 libdispatch.dylib __dispatch_call_block_and_release
10 libdispatch.dylib __dispatch_client_callout
11 libdispatch.dylib __dispatch_root_queue_drain
12 libdispatch.dylib __dispatch_worker_thread2
13 libsystem_pthread.dylib __pthread_wqthread
14 libsystem_pthread.dylib _start_wqthread
The only cause can be the updateRecords.updateValue(ckrecord, forKey: ckrecord.recordID) call in the following function:
func gatherCachedRecords()
{
var ckcaches : [CKCache] = []
*** filling ckcaches from database her ***
updateRecords.removeAll()
for ckcache in ckcaches
{
if let dbrecord = DBRecord.findDBRecord (recid:ckcache.recid)
{
let ckrecord = dbrecord.createCKRecord()
updateRecords.updateValue(ckrecord, forKey: ckrecord.recordID)
}
}
}
updateRecords is a property of the class defined as:
private var updateRecords : [CKRecord.ID: CKRecord] = [:]
gatherCachedRecords is called in global DispatchQueue:
func transferAllTablesToCloud()
{
CKManager.shared.activityIndicator(on: true)
DispatchQueue.global(qos: .utility).async
{
self.dispatchGroup = DispatchGroup()
self.gatherCachedRecords()
*** do some other stuff here ***
}
}
transferAllTablesToCloud is only called once during startup of the app. The only possible problem I could guess is, that updatedRecord is declared on class scope and not locally within the DispatchQueue block, but I have no idea why this could be a problem.
This should only cause trouble if transferAllTablesToCloud would be called more than once and at the same time running concurrently.
The class that hosts all this is a singleton.
I cannot reproduce this in my development environment.
Thanks in advance.
Related
I have a publisher, pipelinePublisher, which runs a combine pipeline of various operations, some of which send a state update to a statePublisher passed in as an argument. pipelinePublisher gets removed on completion of its Combine pipeline:
func myFunction(_ request: MyRequest) -> PassthroughSubject<State, Never> {
let statePublisher = PassthroughSubject<State, Never>()
let presentationSubject = CurrentValueSubject<MyRequest, Error>(request)
var pipelinePublisher: AnyCancellable!
pipelinePublisher = presentationSubject
.eraseToAnyPublisher()
.checkSomething(returningStateTo: statePublisher)
// a few more operators here...
.sink(
receiveCompletion: { [weak self] _ in
self?.cancellables.remove(pipelinePublisher) // Crash happens here
},
receiveValue: { _ in }
)
pipelinePublisher.store(in: &cancellables)
return statePublisher
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
}
However, very occasionally when I call the function multiple times in very quick succession, the app crashes on the line self?.cancellables.remove(pipelinePublisher).
This usually brings up one of two possible stack traces. This first is this:
2022-12-21 15:24:51.926131+0000 MyApp[23082:12933690] -[_NSCoreDataTaggedObjectID member:]: unrecognized selector sent to instance 0x8000000000000000
2022-12-21 15:24:51.931941+0000 MyApp[23082:12933690] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSCoreDataTaggedObjectID member:]: unrecognized selector sent to instance 0x8000000000000000'
*** First throw call stack:
(
0 CoreFoundation 0x000000018040e7c8 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x0000000180051144 objc_exception_throw + 56
2 CoreFoundation 0x000000018041d47c +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x00000001804126c8 ___forwarding___ + 1308
4 CoreFoundation 0x0000000180414b4c _CF_forwarding_prep_0 + 92
5 libswiftCore.dylib 0x000000018be6ee68 $sSh8_VariantV6removeyxSgxF + 160
6 MyApp 0x00000001026c6080 $s12MyApp0A0C17myFunctiony7Combine12AnyPublisherVyAA12StateOs5NeverOGAA19MyRequestVFyAE11SubscribersO10CompletionOy_s5Error_pGcfU_ + 440
7 Combine 0x000000019baa2a70 $s7Combine11SubscribersO4SinkC7receive10completionyAC10CompletionOy_q_G_tF + 364
8 Combine 0x000000019baa2f28 $s7Combine11SubscribersO4SinkCy_xq_GAA10SubscriberA2aGP7receive10completionyAC10CompletionOy_7FailureQzG_tFTW + 20
9 Combine 0x000000019bb541cc $s7Combine10PublishersO7FlatMapV5Outer33_E91C3F00A6DFAAFEA2009FAF507AE039LLC7receive10completionyAA11SubscribersO10CompletionOy_7FailureQzG_tF + 1516
10 Combine 0x000000019bb55328 $s7Combine10PublishersO7FlatMapV5Outer33_E91C3F00A6DFAAFEA2009FAF507AE039LLCy_xq__qd__GAA10SubscriberA2aJP7receive10completionyAA11SubscribersO10CompletionOy_7FailureQzG_tFTW + 20
11 Combine 0x000000019bb53474 $s7Combine10PublishersO7FlatMapV5Outer33_E91C3F00A6DFAAFEA2009FAF507AE039LLC12receiveInner10completion_yAA11SubscribersO10CompletionOy_7FailureQzG_SitF + 1668
12 Combine 0x000000019bb52de4 $s7Combine10PublishersO7FlatMapV5Outer33_E91C3F00A6DFAAFEA2009FAF507AE039LLC4SideV7receive10completionyAA11SubscribersO10CompletionOy_7FailureQzG_tF + 20
13 Combine 0x000000019bac45ec $s7Combine6FutureC7Conduit33_3AE68DE9BADC00342FC052FEBC7D3BA6LLC7fulfillyys6ResultOyxq_GF + 1056
14 Combine 0x000000019bac4960 $s7Combine6FutureC7Conduit33_3AE68DE9BADC00342FC052FEBC7D3BA6LLC6finish10completionyAA11SubscribersO10CompletionOy_q_G_tF + 336
15 Combine 0x000000019bac2de4 $s7Combine6FutureC7promise33_3AE68DE9BADC00342FC052FEBC7D3BA6LLyys6ResultOyxq_GFyAA11ConduitBaseCyxq_GXEfU0_ + 156
16 Combine 0x000000019bac6b28 $s7Combine6FutureC7promise33_3AE68DE9BADC00342FC052FEBC7D3BA6LLyys6ResultOyxq_GFyAA11ConduitBaseCyxq_GXEfU0_TA + 16
17 Combine 0x000000019bae5140 $s7Combine11ConduitListO7forEachyyyAA0B4BaseCyxq_GKXEKF + 212
18 Combine 0x000000019bac2bfc $s7Combine6FutureC7promise33_3AE68DE9BADC00342FC052FEBC7D3BA6LLyys6ResultOyxq_GF + 716
19 Combine 0x000000019bac6b08 $s7Combine6FutureCyACyxq_Gyys6ResultOyxq_GcccfcyAGcfU_TA + 20
20 MyApp 0x0000000102541dd8 $s7Combine6FutureC12MyApps5Error_pRs_rlE9operationACyxsAE_pGxyYaKc_tcfcyys6ResultOyxsAE_pGccfU_yyYaYbcfU_TY2_ + 212
21 MyApp 0x0000000102542705 $s7Combine6FutureC12MyApps5Error_pRs_rlE9operationACyxsAE_pGxyYaKc_tcfcyys6ResultOyxsAE_pGccfU_yyYaYbcfU_TATQ0_ + 1
22 MyApp 0x000000010242f1a1 $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ0_ + 1
23 MyApp 0x000000010242f749 $sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTA.24TQ0_ + 1
24 libswift_Concurrency.dylib 0x00000001b03bedcd _ZL23completeTaskWithClosurePN5swift12AsyncContextEPNS_10SwiftErrorE + 1
)
libc++abi: terminating with uncaught exception of type NSException
The second is in the same place but with the error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber member:]: unrecognized selector sent to instance 0x8000000000000000'
What is causing this? I've tried making pipelinePublisher optional and having a check that it exists before it gets removed but it does actually exist and still crashes. I can't figure this out, please help!
EDIT
I am calling myFunction(_:) by using the method foo which gets a publisher.
static func publisher(forParam: String) -> AnyPublisher<State, Never> {
return Future {
// Do some stuff here
return objects
}
.flatMap { objects in
let request = MyRequest(objects)
return shared.myFunction(request)
}
.eraseToAnyPublisher()
}
static func foo(
param: String,
handler: ((State) -> Void)? = nil
) {
var cancellable: AnyCancellable!
cancellable = publisher(forParam: param)
.sink(
receiveCompletion: { _ in
self.shared.fooItems.cancellables.remove(cancellable) // sometimes crashes here too with the exact same crash!
}, receiveValue: { state in
handler?(state)
}
)
cancellable.store(in: &shared.fooItems.cancellables)
}
A few things to note:
Foo has to use completion block as part of an API.
publisher(forParam:) and therefore myFunction(_:) are only called from foo. However foo is called from many places.
myFunction’s pipelinePublisher cancels by an error that’s thrown at the same time as sending a state and a completion through to foo.
state can be sent to foo without a follow up completion too.
As you can see above, foo also sometimes gets the same error when removing the cancellable.
With help from people in the comments of my question, it looks like I had a race condition possibly caused by threads interacting with each other. I was removing from a Set, but Sets aren't thread safe. I solved this by changing the code to use Subscribers.Sink:
func myFunction(_ request: MyRequest) -> PassthroughSubject<State, Never> {
let statePublisher = PassthroughSubject<State, Never>()
let presentationSubject = CurrentValueSubject<MyRequest, Error>(request)
var pipelinePublisher: AnyCancellable!
pipelinePublisher = presentationSubject
.eraseToAnyPublisher()
.checkSomething(returningStateTo: statePublisher)
// a few more operators here...
.subscribe(Subscribers.Sink(
receiveCompletion: { _ in },
receiveValue: { _ in }
))
pipelinePublisher.store(in: &cancellables)
return statePublisher
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
}
This fixed the problem. Combine handles the clean up of the subscription and the subscriber when the pipeline returns.
This was taken from the answer given here: With Combine, how to deallocate the Subscription after a network request
I have an intermittent (rarely occurring) crash which, so far has only occurred in the wild with reports from AppStore. With the limited crash log, I have not been able to grok the issue.
I am trying to display an App Store Product page view.
Here is the code
The enclosing class includes the SKStoreProductViewControllerDelegate and
the delegate is set to self.
#objc func adTap(sender: UITapGestureRecognizer? = nil) -> Void {
if adAppID.isEmpty {return}
let paramDict = [SKStoreProductParameterITunesItemIdentifier: adAppID]
storeProductViewController.loadProduct(withParameters: paramDict, completionBlock: { (status: Bool, error: Error?) -> Void in
if status {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}
else {
if let error = error {
print("Error: \(error.localizedDescription)")
}
}})
}
The error is triggered at the self.present:
#8 (null) in thunk for #escaping #callee_guaranteed (#unowned Bool, #guaranteed Error?) -> () ()
#7 0x100b68350 in closure #1 in ViewController.adTap(sender:)
#6 (null) in -[UIViewController presentViewController:animated:completion:] ()
#0 (null) in __exceptionPreprocess ()
Dumping the actual cashpoint file shows a SIGABRT:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x1ad1db278 __exceptionPreprocess + 220 (NSException.m:199)
1 libobjc.A.dylib 0x1acf040a4 objc_exception_throw + 56 (objc-exception.mm:565)
2 UIKitCore 0x1b0bcbe0c -[UIViewController _presentViewController:withAnimationController:completion:] + 4880 (UIViewController.m:7185)
3 UIKitCore 0x1b0bce074 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 104 (UIViewController.m:7671)
4 UIKitCore 0x1b0bce570 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 508 (UIViewController.m:7772)
5 UIKitCore 0x1b0bcdfc4 -[UIViewController _presentViewController:animated:completion:] + 196 (UIViewController.m:7678)
6 UIKitCore 0x1b0bce22c -[UIViewController presentViewController:animated:completion:] + 160 (UIViewController.m:7716)
7 MyAppName 0x100b68350 closure #1 in ViewController.adTap(sender:) + 1016 (ViewController.swift:991)
8 MyAppName 0x100b68580 thunk for #escaping #callee_guaranteed (#unowned Bool, #guaranteed Error?) -> () + 60 (<compiler-generated>:0)
9 StoreKit 0x1bba3c1e8 -[SKStoreProductViewController _loadDidFinishWithResult:error:] + 48 (SKStoreProductViewController.m:425)
10 StoreKit 0x1bba3e624 -[SKRemoteProductViewController loadDidFinishWithResult:error:] + 128 (SKRemoteProductViewController.m:61)
///////
I understand that the completion block is an implicitly escaping block, but I do not see how it does not fulfill the block spec (arguments, if indeed that is the issue). Again, this is an intermittent event. Never seen it on a device tethered to Xcode or on one of our untethered devices. Recently it has occurred in the field, once on a iPhone 7 running iOS 13, and once on a X running 12.3.1
/////
Any thoughts would be appreciated
Let me write this as answer, as I see now that my comment may be unclear. The block
if status {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}
accesses some UI elements, yet it may not be running on main thread (since it's inside callback). So first thing I would suspect is that it's crashing if it happens to be called outside of main thread. Hence I would try this:
if status {
DispatchQueue.main.async {
self.storeProductViewController.view.frame.origin.y = 0
let eventParams = ["AppID": self.adAppID]
self.present(self.storeProductViewController, animated: true, completion: nil)
}
}
If it helps, maybe think of better MVC separation...
There is a crash registered on Fabric in my app when I am fetching user's facebook profile information. It is only crashing on release build. I am not able to reproduce the crash even after trying it multiple times. I am fetching the profile in a separate network manager class. I have implemented it using closure and callbacks.
Below is the stack trace and crash report from Fabric.
# OS Version: 11.4.1 (15G77)
# Device: iPhone 6s
# RAM Free: 6%
# Disk Free: 14.3%
#0. Crashed: com.apple.main-thread
0 Roamer 0x104b364a4 LoginViewController.(fetchUserProfile() -> ()).(closure #1) (LoginViewController.swift:250)
1 Roamer 0x104b36d84 partial apply for LoginViewController.(fetchUserProfile() -> ()).(closure #1) (LoginViewController.swift)
2 Roamer 0x104b7ed4c specialized NetworkManager.(fetchFBProfile(((display : Int, status : String, message : String), FBProfileResponse) -> ()) -> ()).(closure #1) (NetworkManager.swift:1234)
3 Roamer 0x104b7e7a4 partial apply for NetworkManager.(fetchFBProfile(((display : Int, status : String, message : String), FBProfileResponse) -> ()) -> ()).(closure #1) (NetworkManager.swift)
4 Roamer 0x104b7e7ec HTTPURLResponse?GraphRequestResult<MyProfileRequest> (NetworkManager.swift)
5 FacebookCore 0x1058dc550 HTTPURLResponse?GraphRequestResult<A> (GraphRequestConnection.swift)
6 FacebookCore 0x1058daaac (HTTPURLResponse?, GraphRequestResult<A>)() (GraphRequestConnection.swift)
7 FacebookCore 0x1058dc8d8 static GraphRequestConnection.sdkRequestCompletion<A where ...> (from : (HTTPURLResponse?, GraphRequestResult<A>) -> ()) -> (FBSDKGraphRequestConnection?, Any?, Error?) -> () empty-list Error first-element-marker HTTPURLResponse (GraphRequestConnection.swift:152)
8 FacebookCore 0x1058dac18 static GraphRequestConnection.sdkRequestCompletion<A where ...> (from : (HTTPURLResponse?, GraphRequestResult<A>) -> ()) -> (FBSDKGraphRequestConnection?, Any?, Error?) -> () empty-list Error first-element-marker HTTPURLResponse (GraphRequestConnection.swift)
9 FacebookCore 0x1058dc5f8 FBSDKGraphRequestConnection?Any?Error? (GraphRequestConnection.swift)
10 FacebookCore 0x1058dc4bc (FBSDKGraphRequestConnection?, Any?, Error?)() (GraphRequestConnection.swift)
11 FacebookCore 0x1058c58bc FBSDKGraphRequestConnection?Any?Error? (AccessToken.swift)
12 FBSDKCoreKit 0x1056a43fc -[FBSDKGraphRequestMetadata invokeCompletionHandlerForConnection:withResults:error:] (FBSDKGraphRequestMetadata.m:48)
13 FBSDKCoreKit 0x1056a1d2c __82-[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:]_block_invoke (FBSDKGraphRequestConnection.m:754)
14 FBSDKCoreKit 0x1056a1b88 -[FBSDKGraphRequestConnection processResultBody:error:metadata:canNotifyDelegate:] (FBSDKGraphRequestConnection.m:818)
15 FBSDKCoreKit 0x1056a163c __64-[FBSDKGraphRequestConnection completeWithResults:networkError:]_block_invoke (FBSDKGraphRequestConnection.m:738)
16 CoreFoundation 0x1825a0a20 -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 216
17 FBSDKCoreKit 0x1056a13e0 -[FBSDKGraphRequestConnection completeWithResults:networkError:] (FBSDKGraphRequestConnection.m:717)
18 FBSDKCoreKit 0x1056a087c -[FBSDKGraphRequestConnection completeFBSDKURLSessionWithResponse:data:networkError:] (FBSDKGraphRequestConnection.m:582)
19 FBSDKCoreKit 0x10569ea54 __36-[FBSDKGraphRequestConnection start]_block_invoke_2 (FBSDKGraphRequestConnection.m:222)
20 libdispatch.dylib 0x181fb8aa0 _dispatch_call_block_and_release + 24
21 libdispatch.dylib 0x181fb8a60 _dispatch_client_callout + 16
22 libdispatch.dylib 0x181fc565c _dispatch_main_queue_callback_4CF$VARIANT$mp + 1012
23 CoreFoundation 0x18266f070 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
24 CoreFoundation 0x18266cbc8 __CFRunLoopRun + 2272
25 CoreFoundation 0x18258cda8 CFRunLoopRunSpecific + 552
26 GraphicsServices 0x184572020 GSEventRunModal + 100
27 UIKit 0x18c5ac758 UIApplicationMain + 236
28 Roamer 0x104b1fbf8 main (DetailsCell.swift:28)
29 libdyld.dylib 0x18201dfc0 start + 4
--
Below is the function in LoginViewController from where I am calling the fetchFBProfile function in NetworkManager:
func fetchUserProfile()
{
NetworkManager.sharedInstance.fetchFBProfile() { [unowned self] (responseStatus: ResponseStatus, responseObj: FBProfileResponse) in
if responseStatus.status == "Success"
{
self.fbSignIn(responseObj)
}
else{
if responseStatus.display == 1
{
self.showBanner(Strings.failureHeaderMsg, responseStatus.message, true, true)
}
else{
self.showBanner(Strings.failureHeaderMsg, Strings.serverErrorMsg, true, true)
}
}
}
}
Below is the fetchFBProfile function in NetworkManager:
func fetchFBProfile( _ completion: #escaping GenericResponseWithObj<FBProfileResponse>) -> Void {
let connection = GraphRequestConnection()
progress.show(style: ProgressStyle())
connection.add(MyProfileRequest()) { response, result in
switch result {
case .success(let response):
let fBProfileResponse = FBProfileResponse()
fBProfileResponse.birthday = response.birthday
fBProfileResponse.email = response.email
fBProfileResponse.gender = response.gender
fBProfileResponse.id = response.id
fBProfileResponse.locale = response.locale
fBProfileResponse.name = response.name
fBProfileResponse.profilePictureUrl = response.profilePictureUrl
completion((0, "Success", "Facebook SignIn Successful"), fBProfileResponse)
case .failed(let error):
print("Custom Graph Request Failed: \(error)")
self.progress.dismiss()
completion((0, "Failure", "Couldn't fetch user response"), FBProfileResponse())
}
}
connection.start()
}
I can't understand the crash report from fabric and also the app is working flawlessly on my end. Any help would be deeply appreciated. Thanks
We've added Today Extension to our app recently.
Its an extension with simple tableView to load data from our server, written in Swift.
But after the extension is online to our users, we've received lots of crash data from Crashlytics and also Apple is reporting same crash issue either.
However, we can't reproduce the crash, or even find the reason of crash, because is crashing on the widgetPerformUpdateWithCompletionHandler method which is called by the system.
Below is the detail of crash log, some information are replaced.
Crashed: com.apple.main-thread
0 MyAppWidget 0x100091d8c MyAppWidgetViewController.(widgetPerformUpdateWithCompletionHandler((NCUpdateResult) -> ()) -> ()).(closure #1) (MyAppWidgetViewController.swift)
1 MyAppKit 0x100603ab4 partial apply for thunk (PostService.swift)
2 MyAppKit 0x100626080 ServiceRequestPerfomer.(performRequest(A, complete : ([B]?, NSError?) -> ()?) -> ()).(closure #1) (ServiceRequestPerformer.swift:35)
3 MyAppKit 0x1006258d4 partial apply for ServiceRequestPerfomer.(performRequest(A, complete : ([B]?, NSError?) -> ()?) -> ()).(closure #1) (ServiceRequestPerformer.swift)
4 MyAppKit 0x100626b34 ServiceRequestPerfomer.((request in _3C50B415180DDC893FFCB75CD7EE7019)(A, complete : (response : Response?, error : NSError?) -> ()?) -> ()).(closure #1) (ServiceRequestPerformer.swift:144)
5 Moya 0x1004b7468 MoyaProvider.(requestNormal(A, queue : OS_dispatch_queue?, progress : (progress : ProgressResponse) -> ()?, completion : (result : Result<Response, Error>) -> ()) -> Cancellable).(closure #1).(closure #1) (Moya.swift:229)
6 Moya 0x1004b8968 MoyaProvider.((sendAlamofireRequest in _1A5616FEE5C423A992964CB19AABD52B)(Request, target : A, queue : OS_dispatch_queue?, progress : (progress : ProgressResponse) -> ()?, completion : (result : Result<Response, Error>) -> ()) -> CancellableToken).(closure #3) (Moya.swift)
7 Moya 0x1004b57b8 partial apply for MoyaProvider.((sendAlamofireRequest in _1A5616FEE5C423A992964CB19AABD52B)(Request, target : A, queue : OS_dispatch_queue?, progress : (progress : ProgressResponse) -> ()?, completion : (result : Result<Response, Error>) -> ()) -> CancellableToken).(closure #3) (Moya.swift)
8 Alamofire 0x1002cff64 Request.(response(queue : OS_dispatch_queue?, completionHandler : (NSURLRequest?, NSHTTPURLResponse?, NSData?, NSError?) -> ()) -> Self).(closure #1).(closure #1) (ResponseSerialization.swift)
9 libdispatch.dylib 0x1819e14bc _dispatch_call_block_and_release + 24
10 libdispatch.dylib 0x1819e147c _dispatch_client_callout + 16
11 libdispatch.dylib 0x1819e6b84 _dispatch_main_queue_callback_4CF + 1844
12 CoreFoundation 0x181f4cd50 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
13 CoreFoundation 0x181f4abb8 __CFRunLoopRun + 1628
14 CoreFoundation 0x181e74c50 CFRunLoopRunSpecific + 384
15 GraphicsServices 0x18375c088 GSEventRunModal + 180
16 UIKit 0x18715e088 UIApplicationMain + 204
17 libxpc.dylib 0x181c38ce0 _xpc_objc_main + 784
18 libxpc.dylib 0x181c3a9dc xpc_main + 200
19 Foundation 0x182a57d60 service_connection_handler + 170
20 PlugInKit 0x18929ac48 -[PKService run] + 544
21 PlugInKit 0x18929a8dc +[PKService main] + 56
22 PlugInKit 0x18929ac6c +[PKService _defaultRun:arguments:] + 20
23 libextension.dylib 0x18286a058 NSExtensionMain + 64
24 libdispatch.dylib 0x181a128b8 (Missing)
And the code of widgetPerformUpdateWithCompletionHandler
func widgetPerformUpdateWithCompletionHandler(completionHandler: ((NCUpdateResult) -> Void)) {
// Perform any setup necessary in order to update the view.
// If an error is encountered, use NCUpdateResult.Failed
// If there's no update required, use NCUpdateResult.NoData
// If there's an update, use NCUpdateResult.NewData
let options: [String: AnyObject] = [DCKPostPopularAttributeName : true.stringValue,
DCKPaginationLimitAttributeName : 5]
postService.posts(options: options) { (posts, error) in
let historyPosts = self.userDefaults.arrayForKey(MyAppWidgetViewController.WidgetPostReadIdentifier) as? [UInt]
if let historyPosts = historyPosts {
self.posts = posts!.filter({ (Post) -> Bool in
return !historyPosts.contains(Post.id)
})
} else {
self.posts = posts!
}
self.tableView.reloadData()
self.tableView.hidden = false;
self.loadingLabel?.hidden = true
self.activityIndicator?.stopAnimating()
let contentSize = self.tableView.contentSize
self.preferredContentSize = CGSizeMake(CGRectGetWidth(self.view.frame), contentSize.height);
self.loadMorePostsIfNeeded()
}
completionHandler(NCUpdateResult.NewData)
}
The strange thing is:
We haven't encountered the crash issue while we're using our Today Extension normally (It should show Unable to load if today extension crashes)
We didn't receive any issue from our users reporting that today extension isn't working.
We've found the same crash log on our device, but the today extension is working normally as 1. described. And also, the time of crash log recorded, I'm not using my phone!
So we're guessing it's a 「fake」crash, the crash is logged, but the extension didn't really crashed.
Does anybody facing the same issue?
Thank you!
Answering my own question,
#matt is right, Now I am calling the completionHandler only when data fetch task completes, instead of always call the completionHandler at the last of widgetPerformUpdateWithCompletionHandler method.
I didn't receive crashes anymore, the problem was solved!
Apple rejected an APP's new version and sent me back crash log, it's hard for me to find the problem even the crash log has been symbolicated in Xcode. From the following, I guess that something wrong in func getGameCenterScore at line 246? Does it tell more problems?
BTW, before calling the func GameCenterScore(), GKLocalPlayer.localPlayer().authenticated is checked, but network is not checked. I have to think it problem here. Any suggestion?
Thx.
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x0000000100054ef4
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 xoxo 0x0000000100054ef4 xoxo.ViewController.(getGameCenterScore (xoxo.ViewController) -> () -> Swift.Int).(closure #1) (ViewController.swift:246)
1 xoxo 0x00000001000546b0 partial apply forwarder for reabstraction thunk helper from #callee_owned (#in ([Swift.AnyObject]!, ObjectiveC.NSError!)) -> (#out ()) to #callee_owned (#owned [Swift.AnyObject]!, #owned ObjectiveC.NSError!) -> (#unowned ()) with unmangled suffix "315" (ViewController.swift:0)
2 xoxo 0x0000000100055110 reabstraction thunk helper from #callee_owned (#owned [Swift.AnyObject]!, #owned ObjectiveC.NSError!) -> (#unowned ()) to #callee_unowned #objc_block (#unowned ObjectiveC.NSArray!, #unowned ObjectiveC.NSError!) -> (#unowned ()) (ViewController.swift:0)
3 GameCenterFoundation 0x000000018e9de3a0 0x18e964000 + 500640
4 libdispatch.dylib 0x0000000197841990 0x197840000 + 6544
5 libdispatch.dylib 0x0000000197841950 0x197840000 + 6480
6 libdispatch.dylib 0x0000000197846208 0x197840000 + 25096
7 CoreFoundation 0x0000000185a877f4 0x1859a8000 + 915444
8 CoreFoundation 0x0000000185a8589c 0x1859a8000 + 907420
9 CoreFoundation 0x00000001859b12d0 0x1859a8000 + 37584
10 GraphicsServices 0x000000018f09f6f8 0x18f094000 + 46840
11 UIKit 0x000000018a576fa8 0x18a500000 + 487336
12 xoxo 0x00000001000636c0 main (AppDelegate.swift:12)
13 libdyld.dylib 0x000000019786ea04 0x19786c000 + 10756
func getGameCenterScore(){
var gameCenterScore = 0
let leaderBoardRequest = GKLeaderboard()
leaderBoardRequest.identifier = "XXXXXXXXXXXXX"
leaderBoardRequest.loadScoresWithCompletionHandler { (scores, error) -> Void in
if (error != nil) {
println("Error: \(error!.localizedDescription)")
} else if (scores != nil) {
let localPlayerScore = leaderBoardRequest.localPlayerScore
gameCenterScore = Int(localPlayerScore.value)
if self.saveData.stringForKey("topScore") == nil {
self.saveData.setValue(gameCenterScore, forKey: "topScore")
self.topScoreLabel.text = "\(gameCenterScore)"
}else{
if gameCenterScore > self.saveData.integerForKey("topScore"){
self.saveData.setValue(gameCenterScore, forKey: "topScore")
self.topScoreLabel.text = "\(gameCenterScore)" // line 246
}
}
}
}
}
Just went through he same thing. A binary rejection for my uploaded app. Finally, got it accepted. I found the line number much like you did. (I used textWrangler and compared the symbolicated text to the original crash. And there was only one line that it could have been. Much like your 216.)
Lines listed as swift:0 are after the crash causing line.
To Solve or eradicate the problem:
1) I found ghosts can linger in my swift code. Clean and rebuild. Try moving the code around.
2) Note that the line where the crash is listed as being may be off by a few lines. The line they listed for my app was a comment. The error was the code above and that code looked okay. I solved it by rewriting in a different way.
3) Look over your code very carefully.
if gameCenterScore > self.saveData.integerForKey("topScore"){`enter code here`
Would this crash if your gameCenterScore == topScore?