com.apple.gamed is crashing when deleting a game [closed] - ios

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have an iOS app that consistently crashes when you try to delete a GKTurnBasedMatch using
[match removeWithCompletionHandler:^(NSError *error){}];
When the completion handler is called, error is nil, meaning that it successfully deleted the match. The match does get deleted (it never re-appears), but at the same time, gamed (the background daemon written by apple that communicates with GameCenter servers) crashes.
Here is what I see in the Console when I delete a game:
Jan 19 20:47:22 Ben-L-iPhone gamed[2233] <Error>: *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0xd000000000b4002a <x-coredata://C0390AE6-6CD0-4A7C-B080-B7649175419A/TurnBasedSession/p45>''
*** First throw call stack:
(0x185ce309c 0x191c61d78 0x1859eb7ac 0x1859fc50c 0x1859fc47c 0x185a7475c 0x185a79034 0x185a797f4 0x185a7a474 0x1922303e0 0x192235d88 0x185a6f3e4 0x185a7a104 0x1859fdbd0 0x100099284 0x185a71b6c 0x1922303e0 0x192235f2c 0x185a71d00 0x10009ce08 0x1000ba8a4 0x192230420 0x1922303e0 0x192235930 0x1922303e0 0x1922373fc 0x192237638 0x1923c5918 0x1923c57a8)
Jan 19 20:47:22 Ben-L-iPhone ReportCrash[2509] <Notice>: ReportCrash acting against PID 2233
Jan 19 20:47:22 Ben-L-iPhone ReportCrash[2509] <Notice>: Formulating crash report for process gamed[2233]
Jan 19 20:47:22 Ben-L-iPhone com.apple.launchd[1] (com.apple.gamed[2233]) <Warning>: (com.apple.gamed) Job appears to have crashed: Abort trap: 6
Jan 19 20:47:22 Ben-L-iPhone ReportCrash[2509] <Notice>: Saved crashreport to /var/mobile/Library/Logs/CrashReporter/gamed_2014-01-19-204722_Ben-L-iPhone.plist using uid: 0 gid: 0, synthetic_euid: 501 egid: 0
Any ideas what could trigger this? I've searched the Apple Dev forums and Google and haven't been able to find someone with a similar problem.
Crash Report Logged
Incident Identifier: C201F189-7311-49E5-96F4-890A65FAA19A
CrashReporter Key: 0b745533f4a51b30bf9654557be6c063d06f1ccc
Hardware Model: iPhone6,1
Process: gamed [2233]
Path: /usr/libexec/gamed
Identifier: gamed
Version: ???
Code Type: ARM-64 (Native)
Parent Process: launchd [1]
Date/Time: 2014-01-19 20:47:22.522 -0600
OS Version: iOS 7.0.4 (11B554a)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread: 11
Last Exception Backtrace:
0 CoreFoundation 0x185ce309c __exceptionPreprocess + 132
1 libobjc.A.dylib 0x191c61d78 objc_exception_throw + 60
2 CoreData 0x1859eb7ac _PFFaultHandlerLookupRow + 1900
3 CoreData 0x1859fc50c -[NSManagedObject(_NSInternalMethods) _newPropertiesForRetainedTypes:andCopiedTypes:preserveFaults:] + 108
4 CoreData 0x1859fc47c -[NSManagedObject(_NSInternalMethods) _newAllPropertiesWithRelationshipFaultsIntact__] + 108
5 CoreData 0x185a7475c -[NSManagedObjectContext(_NSInternalAdditions) _committedSnapshotForObject:] + 72
6 CoreData 0x185a79034 -[NSManagedObjectContext(_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 144
7 CoreData 0x185a797f4 -[NSManagedObjectContext(_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 1092
8 CoreData 0x185a7a474 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 660
9 libdispatch.dylib 0x1922303e0 _dispatch_client_callout + 16
10 libdispatch.dylib 0x192235d88 _dispatch_barrier_sync_f_slow + 352
11 CoreData 0x185a6f3e4 _perform + 124
12 CoreData 0x185a7a104 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] + 184
13 CoreData 0x1859fdbd0 -[NSManagedObjectContext save:] + 840
14 gamed 0x100099284 0x100048000 + 332420
15 CoreData 0x185a71b6c developerSubmittedBlockToNSManagedObjectContextPerform + 100
16 libdispatch.dylib 0x1922303e0 _dispatch_client_callout + 16
17 libdispatch.dylib 0x192235f2c _dispatch_barrier_sync_f_invoke + 48
18 CoreData 0x185a71d00 -[NSManagedObjectContext performBlockAndWait:] + 132
19 gamed 0x10009ce08 0x100048000 + 347656
20 gamed 0x1000ba8a4 0x100048000 + 469156
21 libdispatch.dylib 0x192230420 _dispatch_call_block_and_release + 24
22 libdispatch.dylib 0x1922303e0 _dispatch_client_callout + 16
23 libdispatch.dylib 0x192235930 _dispatch_async_redirect_invoke + 152
24 libdispatch.dylib 0x1922303e0 _dispatch_client_callout + 16
25 libdispatch.dylib 0x1922373fc _dispatch_root_queue_drain + 400
26 libdispatch.dylib 0x192237638 _dispatch_worker_thread2 + 76
27 libsystem_pthread.dylib 0x1923c5918 _pthread_wqthread + 356
28 libsystem_pthread.dylib 0x1923c57a8 start_wqthread + 4
Additional Information
I went back and added logging around the removeMatch. This logging is from the sandbox, but it happens in production too.
Notice, the game is already in a final state (status:GKTurnBasedMatchStatusEnded) right before the match is removed.
As soon as I removed the match, I tried to start a new match. The first try results in a "The operation couldn’t be completed. (Cocoa error 4097.)", the second try nearly 2 minutes later results in a GKServerStatusCode=5000 because the player is no longer authenticated.
2014-01-19 22:23:31.436 KingChase[3432:70b] removing match <GKTurnBasedMatch 0xc50d8f0 - matchID:e0e24a77-fb5c-46a7-b843-21e8becf9735 bundleID:us.pojo.kingchase status:GKTurnBasedMatchStatusEnded message:'Game Over! kctest2 won.' creationDate:2014-01-20 04:17:31 +0000 currentParticipant:(null) participants:<GKTurnBasedParticipant 0xc4e9870 - playerID:G:1972295489 (local player) status:Done matchOutcome:Won lastTurnDate:2014-01-20 04:22:50 +0000 timeoutDate:(null)>,<GKTurnBasedParticipant 0xc439aa0 - playerID:G:1972168157 status:Done matchOutcome:Lost lastTurnDate:2014-01-20 04:23:17 +0000 timeoutDate:(null)> matchData.length:438 matchDataMaximumSize:65536 exchanges:(null)>
2014-01-19 22:23:31.441 KingChase[3432:70b] Match removed.
2014-01-19 22:23:31.442 KingChase[3432:70b] Match cleaned up.
2014-01-19 22:23:40.681 KingChase[3432:70b] Match Making failed. Error Domain=NSCocoaErrorDomain Code=4097 "The operation couldn’t be completed. (Cocoa error 4097.)"
2014-01-19 22:25:30.053 KingChase[3432:70b] Match Making failed. Error Domain=GKErrorDomain Code=6 "The requested operation could not be completed because local player has not been authenticated." UserInfo=0xc527430 {GKServerStatusCode=5000, NSUnderlyingError=0xc5222b0 "The operation couldn’t be completed. status = 5000, missing required header: x-gk-player-id", NSLocalizedDescription=The requested operation could not be completed because local player has not been authenticated.}
The other player was able to delete the game without crashing gamed.
Updated Jan 20, 2014 - 6:32PM CDT - Further Information
I have added logging with every single interaction that I make with GameKit.
Jan 20 17:39:17 Ben-L-iPhone KingChase[3154] <Warning>: GK: [match.currentParticipant.playerID isEqualToString:localPlayer.playerID]
Jan 20 17:39:17 Ben-L-iPhone KingChase[3154] <Warning>: GK: [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:completionHandler];
Jan 20 17:39:18 Ben-L-iPhone KingChase[3154] <Warning>: removing match <GKTurnBasedMatch 0x1669bdb0 - matchID:a182e163-8006-413e-a203-c93d534ac550 bundleID:us.pojo.kingchase status:GKTurnBasedMatchStatusEnded message:'Game Over! kctest1 won.' creationDate:2014-01-20 23:12:32 +0000 currentParticipant:(null) participants:<GKTurnBasedParticipant 0x166ae6f0 - playerID:G:1972168157 (local player) status:Done matchOutcome:Won lastTurnDate:2014-01-20 23:27:14 +0000 timeoutDate:(null)>,<GKTurnBasedParticipant 0x1664d260 - playerID:G:1972295489 status:Done matchOutcome:Lost lastTurnDate:2014-01-20 23:38:15 +0000 timeoutDate:(null)> matchData.length:390 matchDataMaximumSize:65536 exchanges:(null)>
Jan 20 17:39:18 Ben-L-iPhone KingChase[3154] <Warning>: GK: [match removeWithCompletionHandler:^(NSError *error)
Jan 20 17:39:18 Ben-L-iPhone KingChase[3154] <Warning>: Match removed.
Jan 20 17:39:18 Ben-L-iPhone KingChase[3154] <Warning>: Match cleaned up.
Jan 20 17:39:19 Ben-L-iPhone gamed[3125] <Error>: *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0xd00000000024001a <x-coredata://3A4F66E1-B95C-4692-B905-EA1398FB97CE/TurnBasedSession/p9>''
*** First throw call stack:
(0x185ce309c 0x191c61d78 0x1859eb7ac 0x1859fc50c 0x1859fc47c 0x185a7475c 0x185a79034 0x185a797f4 0x185a7a474 0x1922303e0 0x192235d88 0x185a6f3e4 0x185a7a104 0x1859fdbd0 0x10014d284 0x185a71b6c 0x1922303e0 0x192235f2c 0x185a71d00 0x100150e08 0x10016e8a4 0x192230420 0x1922303e0 0x192235930 0x1922303e0 0x1922373fc 0x192237638 0x1923c5918 0x1923c57a8)
I think this now has to do with my calling
[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:completionHandler];
after the game is already complete. I will test the hypothesis when I have time and submit the bug report to Apple.

I have figured out that this problem appears to happen when you call [match removeWithCompletionHandler:^(NSError *error)] from within the completion handler of another GameKit call.
If you look in the log above:
[match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:completionHandler];
is called, and the completionHandler for that method was calling -removeWithCompletionHandler:
I solved this problem using this change:
by executing the removeWithCompletionHandler in this manner:
[match performSelector:#selector(removeWithCompletionHandler:) withObject:^(NSError *error) {} afterDelay:5.0];

Related

iOS - Objective-C: application crash on iOS 10 after libraries upgrade

I have an older Objective-C application that I upgraded recently in order to add new functionalities. I'm using now AFNetworking version 4.0. All is working now even in the newest version of iOS except on iOS 10. When I run it on the simulator, the application crash immediately in the splashSreen. From the logs I know that it's in relation with NSURLSession but can't figure out how to solve it. I've found similar issues but there solutions are not up-to-date.
This is what I have in the thread stack when the crash happened
And this is the crash description from the console log with some previous Firebase calls:
2020-11-19 18:48:11.257 myApp[63563:2715840] Appdelegate, applicationDidBecomeActive
Nov 19 18:48:11 myApp[63563] <Warning>: 6.34.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
Nov 19 18:48:11 myApp[63563] <Notice>: 6.34.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
Nov 19 18:48:11 myApp[63563] <Notice>: 6.34.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
2020-11-19 18:48:11.645 myApp[63563:2715921] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7fa48d318df0 of class __NSCFLocalDataTask was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x600000031ce0> ( <NSKeyValueObservance 0x60000024a200: Observer: 0x6080000f5980, Key path: state, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x608000253ad0> )'
*** First throw call stack: (
1 libobjc.A.dylib 0x0000000112558141 objc_exception_throw + 48
2 CoreFoundation 0x0000000112b5c625 +[NSException raise:format:] + 197
3 Foundation 0x000000010fb52b53 NSKVODeallocate + 294
4 libobjc.A.dylib 0x000000011256cb8e _ZN11objc_object17sidetable_releaseEb + 202
5 libsystem_blocks.dylib 0x0000000113ff799d _Block_release + 111
6 libdispatch.dylib 0x0000000113f6405c _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000113f40c6e _dispatch_continuation_pop + 1020
8 libdispatch.dylib 0x0000000113f4e5db _dispatch_source_invoke + 1401
9 libdispatch.dylib 0x0000000113f42c47 _dispatch_queue_serial_drain + 981
10 libdispatch.dylib 0x0000000113f43669 _dispatch_queue_invoke + 1084
11 libdispatch.dylib 0x0000000113f45ec4 _dispatch_root_queue_drain + 634
12 libdispatch.dylib 0x0000000113f45bef _dispatch_worker_thread3 + 123
13 libsystem_pthread.dylib 0x000000011430d6d5 _pthread_wqthread + 220
14 libsystem_pthread.dylib 0x000000011430d57b start_wqthread + 15 ) libc++abi.dylib: terminating with uncaught exception of type NSException

App Crash on Multi-tasking re-entry (Swift)

Been getting a strange error recently and hope to find a solution here. On double-clicking home and immediately re-entering the app a crash occurs. I've been looking around for a solution in other SO posts but there doesn't seem to be any that come close to this strangeness. The project uses several swift/objc open source libraries and if it is helpful I will post them here as well. I've done everything from cleaning out the AppDelegate, DerivedData/Caches, Pods, the main controllers on re-entry(home, login, auth), and no dice :(
The system logs at the time of crash from a physical device are as follows.
May 22 18:53:47 iPhone-6 SpringBoard[63] <Warning>: BSXPCMessage received error for message: Connection interrupted
May 22 18:53:47 iPhone-6 SpringBoard[63] <Warning>: HW kbd: Failed to set (null) as keyboard focus
May 22 18:53:47 iPhone-6 SpringBoard[63] <Warning>: UNNotificationRegistrarConnectionListener connection invalidated
May 22 18:53:47 iPhone-6 com.apple.debugserver-#(#)PROGRAM:debugserver PROJECT:debugserver-340.3.124
[3269] <Warning>: 1 +0.000000 sec [0cc5/1b0b]: error: ::read ( -1, 0x16e246a38, 1024 ) => -1 err = Bad file descriptor (0x00000009)
May 22 18:53:47 iPhone-6 com.apple.debugserver-#(#)PROGRAM:debugserver PROJECT:debugserver-340.3.124
[3269] <Warning>: Exiting.
May 22 18:53:47 iPhone-6 gputoolsd[3265] <Notice>: schedule invalidation <DYTransport 0x13d504ba0, error: explicit invalidation (6)>
May 22 18:53:47 iPhone-6 gputoolsd[3265] <Notice>: schedule invalidation <DYTransport 0x13d50f850, error: lost transport connection (31)>
May 22 18:53:47 iPhone-6 gputoolsd[3265] <Notice>: terminating daemon 0x13d50f510
May 22 18:53:47 iPhone-6 SpringBoard[63] <Warning>: Application 'UIKitApplication:com.argentapp.ios[0x552c]' exited voluntarily.
May 22 18:53:47 iPhone-6 UserEventAgent[26] <Warning>: 6754616024137: id=com.argentapp.ios pid=3270, state=0
Edit: Back Trace from breakpoint in applicationWillTerminate below. Also the wording of crash may be incorrect as the logs say that the app exited voluntarily upon re-entry and no lldb errors are thrown.
applicationWillResignActive
<UIApplication: 0x14782c3c0>
<NSUserDefaults: 0x14782ee50>
applicationWillTerminate
(lldb) bt
* thread #1: tid = 0x15fd47, 0x00000001000a86b0 Argent`AppDelegate.applicationWillTerminate(application=<unavailable>, self=<unavailable>) -> () + 188 at AppDelegate.swift:254, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x00000001000a86b0 Argent`AppDelegate.applicationWillTerminate(application=<unavailable>, self=<unavailable>) -> () + 188 at AppDelegate.swift:254
frame #1: 0x00000001000a878c Argent`#objc AppDelegate.applicationWillTerminate(UIApplication) -> () + 68 at AppDelegate.swift:0
frame #2: 0x00000001877ed240 UIKit`-[UIApplication _terminateWithStatus:] + 280
frame #3: 0x0000000187a0bff8 UIKit`__102-[UIApplication _handleApplicationDeactivationWithScene:shouldForceExit:transitionContext:completion:]_block_invoke2017 + 796
frame #4: 0x0000000187a0f0c8 UIKit`_runAfterCACommitDeferredBlocks + 292
frame #5: 0x0000000187a1ca80 UIKit`_cleanUpAfterCAFlushAndRunDeferredBlocks + 92
frame #6: 0x000000018774e5a4 UIKit`_afterCACommitHandler + 96
frame #7: 0x00000001825b4728 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
frame #8: 0x00000001825b24cc CoreFoundation`__CFRunLoopDoObservers + 372
frame #9: 0x00000001825b28fc CoreFoundation`__CFRunLoopRun + 928
frame #10: 0x00000001824dcc50 CoreFoundation`CFRunLoopRunSpecific + 384
frame #11: 0x0000000183dc4088 GraphicsServices`GSEventRunModal + 180
frame #12: 0x00000001877c6088 UIKit`UIApplicationMain + 204
frame #13: 0x00000001000a8f1c Argent`main + 144 at AppDelegate.swift:41
frame #14: 0x000000018207a8b8 libdyld.dylib`start + 4
Every other system behavior works as expected and the app functions without a hitch (pressing home and re-opening, lock screen and re-open, opening another app and re-opening, 3d touch navigation etc.). Hope this is descriptive enough, I will try to elaborate more if it is unclear.
XCode Version 7.3
iOS Version 9.3
Swift 2.2

iOS 8 notification action: "Access to item attempted while keychain is locked" error when accessing keychain in "didFinishLaunchingWithOptions"

I am observing a keychain error in the device console thrown by SecItemCopyMatching when acting on an iOS 8 push notification on a locked phone. The detailed repro steps are as follows:
Uninstall all previous versions of the app. Build an Appstore version of the app onto device. Force quit the app.
Increment build number, and build a newer version onto device. This simulates an app update flow. Force quit the app (In real life, the app might get killed by the OS due to memory pressure. Force quitting simulates this behavior).
Send a push notification to the app when the phone is locked.
With the phone locked, swipe left to see the action buttons and press one of the action buttons.
App gets woken up, didFinishLaunchingWithOptions gets called, which tries to access a keychain item. While running SecItemCopyMatching, an error Access to item attempted while keychain is locked shows up in the device console.
The complete error log is shown below. The last line gives the app specific error message.
ReportCrash[32481] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
ReportCrash[32481] <Notice>: ReportCrash acting against PID 31423
diagnosticd[32258] <Error>: error evaluating process info - pid: 31423, punique: 131317
ReportCrash[32481] <Notice>: Formulating crash report for process cfprefsd[31423]
com.apple.xpc.launchd[1] (com.apple.cfprefsd.xpc.daemon[31423]) <Notice>: Service exited due to signal: Bus error: 10
My App[32480] <Error>: assertion failed: 12F70: libxpc.dylib + 71768 [B870B51D-AA85-3686-A7D9-ACD48C5FE153]: 0x7d
Unknown[32480] <Error>:
ReportCrash[32481] <Notice>: Saved report to /Library/Logs/CrashReporter/cfprefsd_2015-07-02-150139_Xianjing-Hus-iPhone.ips
securityd[32279] <Error>: s3dl_query_row decode genp,rowid=8099 failed (-25308): The operation couldn’t be completed. (OSStatus error -25308 - ks_crypt: e00002e2 failed to unwrap item (class 6, bag: 0) Access to item attempted while keychain is locked.)
securityd[32279] <Error>: securityd_xpc_dictionary_handler Okta Verify[32480] copy_matching The operation couldn’t be completed. (OSStatus error -25308 - ks_crypt: e00002e2 failed to unwrap item (class 6, bag: 0) Access to item attempted while keychain is locked.)
My App[32480] <Error>: SecOSStatusWith error:[-25308] The operation couldn’t be completed. (OSStatus error -25308 - Remote error : The operation couldn't be completed. (OSStatus error -25308 - ks_crypt: e00002e2 failed to unwrap item (class 6, bag: 0) Access to item attempted while keychain is locked.))
A few things:
The keychain item's accessibility is set to kSecAttrAccessibleAlways.
As can be seen in the device log above, there is always a cfprefsd process crash prior to the issue.
This issue only occurs on Appstore builds, not on debug builds.
This issue only occurs when trying to act on notification on a locked phone.
This issue only occurs when the app is newly updated, as described in the repro steps above.
Because I force quit the app, when the push notification arrives and I pressed on the action button, my app will be launched in background. didFinishLaunchingWithOptions gets called, and inside this delegate method, I am doing my keychain access which throws the error.
Has anyone seen a similar error and if so, how did you resolve the issue? Any help is appreciated.
Update: Attaching cfprefsd crash log
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: unknown at 0x00000001007d4000
Triggered by Thread: 2
Thread 0 name: Dispatch queue: com.apple.libdispatch-manager
Thread 0:
0 libsystem_kernel.dylib 0x0000000197d88c24 kevent64 + 8
1 libdispatch.dylib 0x0000000197c6de6c _dispatch_mgr_invoke + 272
2 libdispatch.dylib 0x0000000197c5f998 _dispatch_mgr_thread + 48
Thread 1 name: Dispatch queue: com.apple.root.default-qos.overcommit
Thread 1:
0 libsystem_kernel.dylib 0x0000000197da3984 __sigsuspend_nocancel + 8
1 libdispatch.dylib 0x0000000197c6921c _dispatch_sigsuspend + 24
2 libdispatch.dylib 0x0000000197c69200 _dispatch_sig_thread + 44
Thread 2 name: Dispatch queue: src
Thread 2 Crashed:
0 libsystem_platform.dylib 0x0000000197e35300 _platform_memmove + 176
1 libxpc.dylib 0x0000000197e6567c xpc_data_create + 84
2 CoreFoundation 0x0000000185d5a9b8 -[CFPDSource acceptMessage:] + 1956
3 CoreFoundation 0x0000000185dc0da8 __handle_synchronize_message_block_invoke103 + 172
4 CoreFoundation 0x0000000185d57c58 __88+[CFPDSource withSourceForDomain:inContainer:user:byHost:managed:synchronously:perform:]_block_invoke_2 + 24
5 CoreFoundation 0x0000000185d5955c __25-[CFPDSource lockedSync:]_block_invoke + 44
6 libdispatch.dylib 0x0000000197c5d950 _dispatch_client_callout + 12
7 libdispatch.dylib 0x0000000197c671e0 _dispatch_barrier_sync_f_invoke + 72
8 CoreFoundation 0x0000000185d59520 -[CFPDSource lockedSync:] + 80
9 CoreFoundation 0x0000000185d57c0c __88+[CFPDSource withSourceForDomain:inContainer:user:byHost:managed:synchronously:perform:]_block_invoke + 504
10 libdispatch.dylib 0x0000000197c5d950 _dispatch_client_callout + 12
11 libdispatch.dylib 0x0000000197c671e0 _dispatch_barrier_sync_f_invoke + 72
12 CoreFoundation 0x0000000185d576fc +[CFPDSource withSourceForDomain:inContainer:user:byHost:managed:synchronously:perform:] + 364
13 CoreFoundation 0x0000000185dc0508 handle_message + 1312
14 CoreFoundation 0x0000000185dc081c __handle_multi_message_block_invoke_2 + 124
15 libxpc.dylib 0x0000000197e657c0 xpc_array_apply + 76
16 CoreFoundation 0x0000000185dc05f8 handle_message + 1552
17 CoreFoundation 0x0000000185dbffd4 ____CFXPreferencesDaemon_main_block_invoke_5 + 132
18 libxpc.dylib 0x0000000197e64cc8 _xpc_connection_call_event_handler + 64
19 libxpc.dylib 0x0000000197e62bcc _xpc_connection_mach_event + 2156
20 libdispatch.dylib 0x0000000197c5da24 _dispatch_client_callout4 + 12
21 libdispatch.dylib 0x0000000197c6113c _dispatch_mach_msg_invoke + 488
22 libdispatch.dylib 0x0000000197c682d0 _dispatch_queue_drain + 2004
23 libdispatch.dylib 0x0000000197c60664 _dispatch_mach_invoke + 132
24 libdispatch.dylib 0x0000000197c6a314 _dispatch_root_queue_drain + 716
25 libdispatch.dylib 0x0000000197c6bc48 _dispatch_worker_thread3 + 104
26 libsystem_pthread.dylib 0x0000000197e3d228 _pthread_wqthread + 812
27 libsystem_pthread.dylib 0x0000000197e3ceec start_wqthread + 0
This error is definitely caused by trying to access an item that is kSecAttrAccessibleWhenUnlocked while device is still locked. You can tell this just by looking at the following line of the log you've provided:
securityd[32279] <Error>: securityd_xpc_dictionary_handler Okta Verify[32480] copy_matching The operation couldn’t be completed. (OSStatus error -25308 - ks_crypt: e00002e2 failed to unwrap item (class 6, bag: 0) Access to item attempted while keychain is locked.)
Class 6 is kSecAttrAccessibleWhenUnlocked (and kSecAttrAccessibleAlways is class 8) – see slide 15 of this deck for more details – so the behaviour you're seeing is expected.
The real question now is why the item ends up as kSecAttrAccessibleWhenUnlocked while you think it's kSecAttrAccessibleAlways. It is hard to tell without seeing more code and/or having more information, but here are few things to consider:
Keychain items are not removed when app is uninstalled – they do survive app reinstallation/upgrade. So if an earlier version of the app created an item as kSecAttrAccessibleWhenUnlocked it could have just carried on. Try removing the item and creating it again (and check return values of SecItemDelete() and SecItemAdd() to be sure it's done).
Double check that kSecAttrAccessibleAlways is passed to SecItemAdd() so that iOS doesn't apply any defaults on its own.
Note that accessibility class must be passed when creating item (i.e. to SecItemAdd()) and not when retrieving it (i.e. not to SecItemCopyMatching()). This is kind of obvious but it never hurts to reiterate.
If none of the above helps please post relevant code showing how the item is created and then how it's read.
Access to the keychain is blocked when you have a password on your device and the device is locked. So you can't do any actions with the keychain from lock screen if you have a password.

Segmentation Fault when calling NSRegularExpression:matchesInString

I have a crash in my (deployed) iOS-App while starting. It looks like it happens in some lib-functions and I'm not sure how this could be. The console output says
Oct 15 17:05:42 iPadMiniR MyApp[260] <Warning>: INFO: downloading package data 5 of 5...
Oct 15 17:05:42 iPadMiniR ReportCrash[261] <Error>: task_set_exception_ports(B07, 400, D03, 0, 0) failed with error (4: (os/kern) invalid argument)
Oct 15 17:05:42 iPadMiniR ReportCrash[261] <Notice>: ReportCrash acting against PID 260
Oct 15 17:05:42 iPadMiniR diagnosticd[150] <Error>: error evaluating process info - pid: 260, punique: 260
Oct 15 17:05:42 iPadMiniR ReportCrash[261] <Notice>: Formulating crash report for process myApp[260]
so I analyzed the Crash Report:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000058
Triggered by Thread: 4
[...]
Thread 4 name: Dispatch queue: com.apple.root.default-qos
Thread 4 Crashed:
0 libobjc.A.dylib 0x00000001946d3bd0 objc_msgSend + 16
1 Foundation 0x0000000184ac884c -[NSSimpleRegularExpressionCheckingResult initWithRanges:count:regularExpression:] + 176
2 Foundation 0x0000000184aaf2a4 -[NSRegularExpression(NSMatching) enumerateMatchesInString:options:range:usingBlock:] + 1340
3 Foundation 0x0000000184ac8720 -[NSRegularExpression(NSMatching) matchesInString:options:range:] + 152
4 myApp [...]
I know what a Segfault is but I don't understand, why it can happen in a Library function. I already searched in Apple's developer documentation of NSRegularExpression (under enumerateMatchesInString:options:range:usingBlock: and matchesInString:options:range:) and googled for NSSimpleRegularExpressionCheckingResult, but I didn't find a thing that helps. In similar questions here on StackOverflow, the SIGSEGV occurs not in library functions but in the user's code.
My question is: How could a Segfault in this context occur? Doesn't the objective-C-Library-Functions check pointers? Or could it be that a pointer become dangled between the check and the usage (weak pointers, but I don't have any of them)?
I'm pretty new to iOS development, so thanks for any help :)
I use XCode 6.0.1 and iOS 8.0.2.

Does anyone know whats going on here ? Core Data / iCloud

So whats happening here is the app has just received the NSPersistentStoreDidImportUbiquitousContentChangesNotification, and I have just called
- (void)storesDidUpdate:(NSNotification*)note {
FLOG(#"storesDidUpdate ");
[_managedObjectContext mergeChangesFromContextDidSaveNotification:note];
// Refresh user Interface
[[NSNotificationCenter defaultCenter] postNotificationName:#"iProjectCoreDataUpdated"
object:self];
[self updateDetails];
}
And now the app is trying to update a UITextView with a fresh copy of text by simply doing the following:
self.detailText.attributedText = [self.detailItem valueForKey:#"scope"];
Where detailItem is a NSManagedObject retrieved prior to receiving the update from iCloud.
Not sure why the textContainer is complaining or what its complaining about, and also not sure why importing logs is happening because I have already received a notification that its done!
Strangely other UITableViews update correctly if I just call reloadData.
Any ideas on whether I am doing something wrong here? Note that if I don't try and update the textView it works fine and if I close the view and go back to it then I get the correct data.
Also when I restart the app all the data is there, no corruptions or anything, in fact the app seems remarkably robust in most respects when it comes to the Core Data store, despite things blowing up on either side of iCloud!
Oh and the reloadFetchedResults is a bit misleading because I don't seem to need to do that, so the method name is a hangover from the past, all I am doing is refreshing values in the UI in this call.
2013-10-09 07:25:53.783 MyApp[4509:510b] OpeningViewController.reloadFetchedResults: called
2013-10-09 07:25:53.786 MyApp[4509:510b] InfoDetailViewController.reloadFetchedResults: called in InfoDetailViewController
2013-10-09 07:25:53.788 MyApp[4509:510b] * Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation/UIFoundation-258/UIFoundation/TextSystem/NSLayoutManager_Private.m:1510
2013-10-09 07:25:53.793 MyApp[4509:510b] -_PFUbiquityRecordImportOperation main: CoreData: Ubiquity: Error importing transaction log:
transactionLogLocation: : /var/mobile/Library/Mobile Documents/HHHHHHNNNN~com~mycompany~MyApp/CoreData/New Document/duncangroenewald~simAABC628E-9D5E-58F7-9B8D-0BC724C6D0C8/New Document/W8MckEJ0x2d~HZZIeUH2be6hs41TEOONzKIrCuLcuP4=/6C953E7C-B2AF-47F7-B828-DD062B96415D.1.cdt
transactionNumber: 5
, exception: Only run on the main thread!
User Info: (null)
2013-10-09 07:25:53.803 MyApp[4509:510b] -_PFUbiquityRecordsImporter operation:failedWithError:: CoreData: Ubiquity: Import operation encountered an error: Error Domain=NSCocoaErrorDomain Code=134060 "The operation couldn’t be completed. (Cocoa error 134060.)" UserInfo=0x16d882c0 {exception=Only run on the main thread!}
userInfo: {
exception = "Only run on the main thread!";
}. While trying to import the log file at the URL:
transactionLogLocation: : /var/mobile/Library/Mobile Documents/HHHHHHNNNN~com~mycompany~MyApp/CoreData/New Document/duncangroenewald~simAABC628E-9D5E-58F7-9B8D-0BC724C6D0C8/New Document/W8MckEJ0x2d~HZZIeUH2be6hs41TEOONzKIrCuLcuP4=/6C953E7C-B2AF-47F7-B828-DD062B96415D.1.cdt
transactionNumber: 5
2013-10-09 07:25:53.809 MyApp[4509:510b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(0x2ff23f53 0x3a6996af 0x2ff23e2d 0x308cb1df 0x3796643d 0x37966185 0x3798f7bb 0x379926f7 0x37992759 0x379b378b 0x379b331f 0x379b2f0d 0x3273b05d 0x129717 0x2fee6121 0x2fe5a317 0x3083edcd 0x308436ab 0x118263 0x2fee6121 0x2fe5a317 0x2fd8c69f 0x2fd8cc93 0x2fd813dd 0x3085197b 0x308f5b35 0x3ab83297 0x3ab8309b 0x3ab83d15 0x3ab83f8d 0x3acbedbf 0x3acbec84)
libc++abi.dylib: terminating with uncaught exception of type NSException
EDIT:
I have posted some sample Core Data/iCloud apps for iOS and OSX here - they include background threads for loading/deleting data as well as iCloud sync. Hopefully address the issue described here. http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/
OK here is what seems to fix it - I guess I never realised that receiving a notification would run on another thread. Is that normal behaviour, are all Core Data notifications you receive called on a background thread ? If so do you always have to make sure anything you do is then running on the correct thread ?
- (void)storesDidUpdate:(NSNotification*)note {
FLOG(#"storesDidUpdate ");
[_managedObjectContext mergeChangesFromContextDidSaveNotification:note];
[[NSOperationQueue mainQueue] addOperationWithBlock:^ {
//Your code goes in here
LOG(#" Main Thread Code");
// Refresh user Interface
[[NSNotificationCenter defaultCenter] postNotificationName:#"CoreDataUpdatedNotification"
object:self];
}];
}
EDIT:
I have finally gotten around to documenting how I got Core Data and iCloud to work pretty reliably, including handling moving to and from iCloud in response to the use changing their Use iCloud preference settings. I was unable to find a good explanation with working code when I was trying to figure out how to get it working so I hope this proves useful to others. Included is a video of the app working so you can see how it behaves to help you figure out if it's what you are wanting to achieve.
http://ossh.com.au/design-and-technology/software-development/
I got the same problem. It was exactly the issue #John Rogers explained.
I created UITextViews and in the background I called a URL to get some data which should be inserted into my generated UITextViews. But the Problem was the method sendAsynchronousRequest which will be called in background and cause the crash in my case.
I could solve the problem by performing the specific selector on main thread when receiving my data. So maybe you can insert you're method call into another method and call it this way:
[self performSelectorOnMainThread:#selector(received:)
withObject:data
waitUntilDone:YES];
This way you get back to the main thread again.
Reading all the answers+comments (and your fix) - I think it should be noted you MUST update any UI control from the main thread only.
I assume the [self updateDetails]; calls the self.detailText.attributedText = [self.detailItem valueForKey:#"scope"]; code?...which is the actual code that updates the UI?
Assume that, then You could execute the call to -updateDetails using -performSelectorOnMainThread: or in the -updateDetails check that you are executing on the main thread ([NSThread isMainThread]) and wrap the UI update code there so the caller doesn't care what thread they call -updateDetails from.
Yes, I get that but I don't do anything on any threads so something else must be. I am updating a UITextView and I guess its possible something in that is causing a failure. I am not clear on why this would have anything to do with the ubiquityImporter - perhaps someone who can interpret this stuff below can point me in the right direction. Am I somehow running something on the wrong thread ?
First throw call stack:
(
0 CoreFoundation 0x027c55e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019238b6 objc_exception_throw + 44
2 CoreFoundation 0x027c5448 +[NSException raise:format:arguments:] + 136
3 Foundation 0x01062960 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
4 UIFoundation 0x01b33131 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 419
5 UIFoundation 0x01b32e16 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2083
6 UIFoundation 0x01b67675 _enableTextViewResizing + 234
7 UIFoundation 0x01b6b275 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 688
8 UIFoundation 0x01b6b2fa -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 82
9 UIFoundation 0x01b93d35 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 153
10 UIFoundation 0x01b93870 -[NSTextStorage processEditing] + 462
11 UIFoundation 0x01b93419 -[NSTextStorage endEditing] + 80
12 UIFoundation 0x01b934a3 -[NSTextStorage coordinateEditing:] + 66
13 UIKit 0x007f4f48 -[UITextView setAttributedText:] + 254
14 MyApp 0x00027d7a -[WBSDetailViewController displayItem] + 3146
15 MyApp 0x00028c6c -[WBSDetailViewController refreshUI:] + 156
16 Foundation 0x01088e39 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
17 CoreFoundation 0x02821524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
18 CoreFoundation 0x0277907b _CFXNotificationPost + 2859
19 Foundation 0x00fc2b91 -[NSNotificationCenter postNotificationName:object:userInfo:] + 98
20 Foundation 0x00fd206a -[NSNotificationCenter postNotificationName:object:] + 55
21 MyApp 0x00031095 -[BaseAppDelegate storesDidUpdate:] + 293
22 Foundation 0x01088e39 __57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke + 40
23 CoreFoundation 0x02821524 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20
24 CoreFoundation 0x0277907b _CFXNotificationPost + 2859
25 Foundation 0x00fddd7b -[NSNotificationCenter postNotification:] + 121
26 CoreData 0x0173c5f4 -[_PFUbiquityRecordsImporter postImportNotificationForStoreName:andLocalPeerID:withUserInfo:] + 1892
27 CoreData 0x0173cbc2 -[_PFUbiquityRecordsImporter operationDidFinish:] + 706
28 CoreData 0x0172e8ce -[_PFUbiquityRecordImportOperation main] + 15102
29 Foundation 0x0108aa69 -[__NSOperationInternal _start:] + 671
30 Foundation 0x01007798 -[NSOperation start] + 83
31 Foundation 0x0108cd34 __NSOQSchedule_f + 62
32 libdispatch.dylib 0x05b794b0 _dispatch_client_callout + 14
33 libdispatch.dylib 0x05b67088 _dispatch_queue_drain + 450
34 libdispatch.dylib 0x05b66e85 _dispatch_queue_invoke + 126
35 libdispatch.dylib 0x05b67e25 _dispatch_root_queue_drain + 83
36 libdispatch.dylib 0x05b6813d _dispatch_worker_thread2 + 39
37 libsystem_pthread.dylib 0x05f05dab _pthread_wqthread + 336
38 libsystem_pthread.dylib 0x05f09cce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Resources