In iOS10, is it possible to access Keychain from within a static library/framework, for unit testing - keychain

Until Xcode 8/iOS 10, I was able to access the Keychain from within the unit tests of a static library. After upgrading, I get an error, see stack trace:
failed: caught "NSInternalInconsistencyException", "Couldn't add the Keychain Item."
(
0 CoreFoundation 0x000000010b2a734b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ad0821e objc_exception_throw + 48
2 CoreFoundation 0x000000010b2ab442 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010a89eedd -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 MyLibTests 0x0000000117366dea -[KeychainItemWrapper writeToKeychain] + 970
5 MyLibTests 0x000000011736614a -[KeychainItemWrapper setObject:forKey:] + 218
6 MyLibTests 0x000000011736a794 -[MyUserManager(Credentials) save] + 196
7 PawPointsLibTests 0x0000000116ef5490 -[MyLibTest tearDown] + 256
8 XCTest 0x000000010a6e0547 __24-[XCTestCase invokeTest]_block_invoke_2 + 1304
9 XCTest 0x000000010a7189d4 -[XCTestContext performInScope:] + 190
10 XCTest 0x000000010a6e001c -[XCTestCase invokeTest] + 255
11 XCTest 0x000000010a6e0835 -[XCTestCase performTest:] + 457
12 XCTest 0x000000010a6dd8fd -[XCTestSuite performTest:] + 491
13 XCTest 0x000000010a6dd8fd -[XCTestSuite performTest:] + 491
14 XCTest 0x000000010a6dd8fd -[XCTestSuite performTest:] + 491
15 XCTest 0x000000010a6c9b0c __25-[XCTestDriver _runSuite]_block_invoke + 51
16 XCTest 0x000000010a6eafc3 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 602
17 XCTest 0x000000010a6c99a9 -[XCTestDriver _runSuite] + 436
18 XCTest 0x000000010a6ca7a2 -[XCTestDriver _checkForTestManager] + 287
19 XCTest 0x000000010a719f5c _XCTestMain + 628
20 xctest 0x000000010a64c922 xctest + 6434
21 libdyld.dylib 0x000000010e01368d start + 1
22 ??? 0x0000000000000005 0x0 + 5
Any ideas how to make this work again. At the app level, enabling keychain sharing and adding entitlements took care of it, but that won't help me b/c I need to be able to test the library independently before shipping, since the app development is done by a different team. I am using Apple's old example for how to add to keychain, but have tried other libraries, all with the same result.

You can try this workaround:
Add an app target to your project.
Enable keychain sharing and adding entitlement for the app you added.
Go to the test target of your project. Under General->Testing->Host application, add the application you created.
Run the tests

Related

iOS crash reports not get the correct line number

i want to look my mistake line of my app:
0 CoreFoundation 0x36e008a7 __exceptionPreprocess + 186
1 libobjc.A.dylib 0x33217259 objc_exception_throw + 32
2 CoreFoundation 0x36e00789 +[NSException raise:format:] + 0
3 CoreFoundation 0x36e007ab +[NSException raise:format:] + 34
4 Foundation 0x32a8e5b3 +[NSJSONSerialization JSONObjectWithData:options:error:] + 66
5 myshine 0x001f68d1 _mh_execute_header + 1046737
6 myshine 0x000fb27b _mh_execute_header + 17019
7 UIKit 0x35009cab -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1182
8 UIKit 0x350037dd -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 408
9 UIKit 0x34fd1ac3 -[UIApplication handleEvent:withNewEvent:] + 1010
10 UIKit 0x34fd1567 -[UIApplication sendEvent:] + 54
11 UIKit 0x34fd0f3b _UIApplicationHandleEvent + 5826
12 GraphicsServices 0x34f1e22b PurpleEventCallback + 882
13 CoreFoundation 0x36dd4523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 38
14 CoreFoundation 0x36dd44c5 __CFRunLoopDoSource1 + 140
15 CoreFoundation 0x36dd3313 __CFRunLoopRun + 1370
16 CoreFoundation 0x36d564a5 CFRunLoopRunSpecific + 300
17 CoreFoundation 0x36d5636d CFRunLoopRunInMode + 104
18 UIKit 0x3500286b -[UIApplication _run] + 550
19 UIKit 0x34fffcd5 UIApplicationMain + 1080
20 myshine 0x000faa33 _mh_execute_header + 14899
21 myshine 0x000f9270 _mh_execute_header + 8816
mac04:skydrive pwang$ dwarfdump --uuid myshine.app.dSYM
UUID: DEB2D948-0339-31BF-B3A3-CE21B73171AC (armv7) myshine.app.dSYM/Contents/Resources/DWARF/myshine
UUID: 90212FF0-80ED-3083-9DFB-FC883F1EDBD0 (armv7s) myshine.app.dSYM/Contents/Resources/DWARF/myshine
mac04:skydrive pwang$ dwarfdump --uuid myshine.app/myshine
UUID: DEB2D948-0339-31BF-B3A3-CE21B73171AC (armv7) myshine.app/myshine
UUID: 90212FF0-80ED-3083-9DFB-FC883F1EDBD0 (armv7s) myshine.app/myshine
mac04:skydrive pwang$ /Applications/Xcode.app/Contents/Developer/usr/bin/atos -arch armv7 -o myshine.app/myshine 0x001f68d1
0x001f68d1 (in myshine)
it give me the 0x001f68d1,not the mistake line. can you tell me what should i do can get the correct line
Here are some links to how you can do attempt to read that crash report:
Symbolicating iPhone App Crash Reports
Ray Wenderlich tutorial HERE
That being said, sometimes you will not get the correct line for an error in your project. For example if you have instantiated a an unretained pointer for an object and something else tries to point to it after the retain count is zero, that will cause an error (bad access), but in reality the place where that bad access crash happens is not the place where the issue is (the declaration of the pointer). My first step (usually before trying to analyze the crash report, unless it is obvious), is to set a break point and then step through the code until the app crashes. You can also use break points and customize them to continue while sending output to the debugger or playing a sound, etc. See THIS tutorial for some info on debugging techniques.
Logs suggest that NSJSONSerialization is raising an exception. Write a try-catch block and put the exception causing code in it. Print the exception details, and you will come to know the issue.
You can also add a breakpoint for objc_exception_throw and +[NSException raise:format:] and debug the code. When the error condition occurs you will be able to trace the chain of events that caused this error. Refer to this link to see how to add these breakpoints.

Crash with MapKit on iOS 6

I have not been able to reproduce this particular crash myself but it has been reported via our crash reporting tool and is being experienced by several hundred of our users. Finding it hard to debug or reproduce.
It happens on all hardware platforms but only on iOS 6. Any help or insights will be highly appreciated.
Exception Type:SIGSEGVCode:SEGV_ACCERR
Fatal Exception
Thread 0 Crashed
0 MapKit _remove(objc_object*, MKQuadTrieNode*) + 13
1 MapKit -[MKQuadTrie remove:] + 54
2 MapKit -[MKAnnotationContainerView observeValueForKeyPath:ofObject:change:context:] + 252
3 Foundation NSKeyValueNotifyObserver + 272
4 Foundation NSKeyValueWillChange + 572
5 Foundation -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 180
6 Foundation NSKVOForwardInvocation + 130
7 CoreFoundation ___forwarding___ + 626
8 CoreFoundation _CF_forwarding_prep_0 + 24
9 MapKit -[MKUserLocation _updateCoordinate] + 106
10 MapKit -[MKUserLocation setLocation:] + 106
11 MapKit -[MKMapView(UserPositioningInternal) locationManagerUpdatedLocation:] + 994
12 CoreFoundation -[NSArray makeObjectsPerformSelector:withObject:] + 206
13 MapKit -[MKLocationManager _reportLocationStatus:] + 66
14 MapKit -[MKLocationManager locationProvider:didUpdateLocation:] + 1540
15 MapKit -[MKCoreLocationProvider locationManager:didUpdateLocations:] + 864
16 CoreLocation -[CLLocationManager onClientEventLocation:] + 1614
17 CoreLocation __CLClientInvokeCallback_block_invoke_0 + 64
18 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
19 CoreFoundation __CFRunLoopDoBlocks + 160
20 CoreFoundation __CFRunLoopRun + 1450
21 CoreFoundation CFRunLoopRunSpecific + 356
22 CoreFoundation CFRunLoopRunInMode + 104
23 GraphicsServices GSEventRunModal + 74
24 UIKit UIApplicationMain + 1120
25 App Name main.m line 14 main + 14
Try setting the delegate method of the locationManager to nil in the dealloc method of the class you are using it in
Something like this:
-(void) dealloc
{
self.locationManager.delegate = nil;
}
What might be happening is that the object is being deallocated (maybe due to low memory) and the location manager is trying to send a message to a non existing delegate.

sigsegv crash on iphone from crittercism

I've got a couple sigsegv crashes coming in from crittercism, but I'm not quite sure how to start going about debugging. The only line of code that's mine is the main call from the start of the crashed thread.
Copying the crashed thread's stack trace from crittercism:
Reason:
24-Sep-12
02:38:14 PM SIGSEGV
main (main.m:11)
Stack:
0
0 libobjc.A.dylib 0x356265b0 objc_msgSend + 15
1
1 UIKit 0x3861c313 + 1310
2
2 UIKit 0x386337cf + 206
3
3 UIKit 0x385ef80b + 258
4
4 QuartzCore 0x34f56d63 + 214
5
5 QuartzCore 0x34f56901 + 460
6
6 QuartzCore 0x34f57835 + 16
7
7 QuartzCore 0x34f5721b + 238
8
8 QuartzCore 0x34f57029 + 316
9
9 UIKit 0x386786e5 + 572
10
10 UIKit 0x386784a3 + 66
11
11 UIKit 0x38677391 + 1464
12
12 UIKit 0x385ed1ef + 2458
13
13 UIKit 0x385ec6d5 + 72
14
14 UIKit 0x385ec123 + 6154
15
15 GraphicsServices 0x3779f5a3 + 590
16
16 CoreFoundation 0x372f0683 + 14
17
17 CoreFoundation 0x372efee9 + 212
18
18 CoreFoundation 0x372eecb7 + 646
19
19 CoreFoundation 0x37261ebd CFRunLoopRunSpecific + 356
20
20 CoreFoundation 0x37261d49 CFRunLoopRunInMode + 104
21
21 GraphicsServices 0x3779e2eb GSEventRunModal + 74
22
22 UIKit 0x38640301 UIApplicationMain + 1120
23
23 MyApp 0x35bf main (main.m:11)
First, you'll need to "symbolicate" the crash log. There are plenty of web pages out there to instruct you on that.
Since this stack ends at objc_msgSend, the most likely cause is a dangling pointer.
To debug those, I recommend using NSZombies. If you are testing on the simulator, you might try "Guard malloc".
This crash is caused by invoking a method on a pointer to an object that was already deallocated. It is a very common ref count error somewhere in your code that holds on the UIKit elements. But, what you should do at a matter of practice is upload your .DSYM file to the crittercism. It can be done manually via the website or via a Web API call as part of your automatic build process.

Test Flight Crash Report

I am keep on getting crash from my application in which i have integrate test flight 8.2 beta. Will You please tell me what does this crash report means. I think this is due to test flight sdk.
0 CoreFoundation 0x37c938bf __exceptionPreprocess + 163
1 libobjc.A.dylib 0x317791e5 objc_exception_throw + 33
2 CoreFoundation 0x37c937b9 +[NSException raise:format:] + 1
3 CoreFoundation 0x37c937db +[NSException raise:format:] + 35
4 CoreFoundation 0x37c00671 -[__NSCFDictionary setObject:forKey:] + 161
5 Foundation 0x31b4971b -[NSMutableDictionary(NSKeyValueCoding) setValue:forKey:] + 23
6 AppName 0x0014a1cb -[TFAirTrafficController getSystemLog:] + 731
7 AppName 0x001486dd -[TFAirTrafficController checkForOldLogs] + 249
8 AppName 0x00148849 -[TFAirTrafficController checkForOldData:] + 49
9 Foundation 0x31b39a91 -[NSThread main] + 73
10 Foundation 0x31bcd5a1 __NSThread__main__ + 1049
11 libsystem_c.dylib 0x360bbc1d _pthread_start + 321
12 libsystem_c.dylib 0x360bbad8 thread_start + 8
You are trying to insert nil into a dictionary in [TFAirTrafficController getSystemLog:]. Make sure the object is not nil before attempting to insert it. Also make sure your key is not nil as well.
UPDATE: As pointed out by Nikolai TFAirTrafficController is test flight's code. So I guess the real solution is to make sure you are on the latest stable TestFlight SDK

App Crashing in NSURLConnection

I am trying to figure out what is causing this crash. I have built and given the app to our testers but we cannot seem to reproduce this reliably. It just happens sometimes...
Thread 0 Crashed:
0 libobjc.A.dylib 0x000027da objc_msgSend + 18
1 Foundation 0x00032896 -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] + 62
2 Foundation 0x00032818 _NSURLConnectionDidFinishLoading + 72
3 CFNetwork 0x00010dd8 URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) + 160
4 CFNetwork 0x00004ad4 URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 96
5 CFNetwork 0x000049c4 URLConnectionClient::processEvents() + 64
6 CFNetwork 0x00004976 URLConnection::multiplexerClientPerform(RunLoopMultiplexer*) + 30
7 CFNetwork 0x000048f4 MultiplexerSource::perform() + 120
8 CFNetwork 0x00004872 MultiplexerSource::_perform(void*) + 2
9 CoreFoundation 0x00055f1e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
10 CoreFoundation 0x00027ba0 __CFRunLoopDoSources0 + 376
11 CoreFoundation 0x00027444 __CFRunLoopRun + 224
12 CoreFoundation 0x00027270 CFRunLoopRunSpecific + 224
13 CoreFoundation 0x00027178 CFRunLoopRunInMode + 52
14 GraphicsServices 0x000045ec GSEventRunModal + 108
15 GraphicsServices 0x00004698 GSEventRun + 56
16 UIKit 0x0000411c -[UIApplication _run] + 396
17 UIKit 0x00002128 UIApplicationMain + 664
18 myapp 0x000020d8 main (main.m:14)
19 myapp 0x0000208c start + 32
Any advice would be greatly appreciated. The app is built in XCode 3.2.4 using SDK 4.1.
Cheers...
I would try turning on NSZombieEnabled and see if that sheds any light on the issue. Is the delegate for the connection still around and valid?
Ben has some sound advice. Turn NSZombieEnabled to on.
I can tell you with almost 100% certainty that it is crashing because you have a nil object when the delegate is attempting to send it a message.
The fact that it is only crashing sometimes, tells me that you are probably using autorelease. Autorelease never decrements the retain count at exactly the same time, so sometimes your object will still be alive when it gets a delegate message and the app works. However, sometimes that object will have been released and the app crashes.