How to "Take Priority" of Audio Playback? - swift

I have an audio-playback app that crashes when returning from another audio-playing app when the user attempts to re-start playback. My app works great on it's own and will handle background playback, etc; however when returning from Spotify-like apps it crashes when it starts it's own playback.
I'm guessing there's some sort of "priority" of audio that I should be handling? And taking that priority "back" from whatever audio app previously had it? Just looking for a direction to start looking....thanks!
Backtrace:
thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001be4fdec4 libsystem_kernel.dylib__pthread_kill + 8
frame #1: 0x00000001be41d724 libsystem_pthread.dylibpthread_kill$VARIANT$armv81 + 216
frame #2: 0x00000001be36d844 libsystem_c.dylibabort + 100
frame #3: 0x00000001be4c67d4 libc++abi.dylibabort_message + 128
frame #4: 0x00000001be4c69c4 libc++abi.dylibdemangling_terminate_handler() + 296
frame #5: 0x00000001be42e258 libobjc.A.dylib_objc_terminate() + 124
frame #6: 0x00000001be4d3304 libc++abi.dylibstd::__terminate(void (*)()) + 16
frame #7: 0x00000001be4d2ed8 libc++abi.dylib__cxa_rethrow + 144
frame #8: 0x00000001be42e158 libobjc.A.dylibobjc_exception_rethrow + 40
frame #9: 0x00000001be67eb4c CoreFoundationCFRunLoopRunSpecific + 576
frame #10: 0x00000001c861f328 GraphicsServicesGSEventRunModal + 104
frame #11: 0x00000001c278c63c UIKitCoreUIApplicationMain + 1936
frame #12: 0x00000001047c0e78 Sequencer`main at AppDelegate.swift:23:7
frame #13: 0x00000001be508360 libdyld.dylib`start + 4

Related

How to debug with breakpoint when crash line is the App Delegate?

Ever since upgrading to the latest Xcode, I've experienced random/intermittent crashes on app launch that I can only reproduce by launching the app n times and waiting for it to return. The line that the app crashes on is the top of the App Delegate:
class AppDelegate: UIResponder, UIApplicationDelegate {
I don't know how I'd set a breakpoint here and what I could gather from it. The reported cause of the crash is an NSException error on Thread 1:
[_NSTaggedDate countByEnumeratingWithState:objects:count]: unrecognized selector sent to instance 0x8000000000000000
Backtrace:
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x000000019b7c6d88 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x000000019b6df1e8 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 136
frame #2: 0x000000019b632934 libsystem_c.dylib`abort + 100
frame #3: 0x000000019b79acc0 libc++abi.dylib`abort_message + 128
frame #4: 0x000000019b78ce10 libc++abi.dylib`demangling_terminate_handler() + 296
frame #5: 0x000000019b6f3e80 libobjc.A.dylib`_objc_terminate() + 124
frame #6: 0x000000019b79a14c libc++abi.dylib`std::__terminate(void (*)()) + 16
frame #7: 0x000000019b79a0e4 libc++abi.dylib`std::terminate() + 44
frame #8: 0x000000019b6f3e04 libobjc.A.dylib`objc_terminate + 12
frame #9: 0x0000000105e2b744 libdispatch.dylib`_dispatch_client_callout + 36
frame #10: 0x0000000105e39710 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 976
frame #11: 0x000000019b94f7fc CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
frame #12: 0x000000019b94a6d0 CoreFoundation`__CFRunLoopRun + 1724
frame #13: 0x000000019b949ce8 CoreFoundation`CFRunLoopRunSpecific + 424
frame #14: 0x00000001a5a9438c GraphicsServices`GSEventRunModal + 160
frame #15: 0x000000019fa78444 UIKitCore`UIApplicationMain + 1932
frame #16: 0x0000000100fc866c FXTracker`main at AppDelegate.swift:8:7
frame #17: 0x000000019b7d18f0 libdyld.dylib`start + 4
In the debug navigator window, it's opened to Thread 1 and there is a drop-down called Original Exception Backtrace which looks like this:
0 _exceptionPreprocess
9 Sequence<>.contains(_:)
10 closure #3 in closure #1 in closure #2 in FXEditorViewController.loadBadges()
19 UIApplicationMain
20 main
21 start
Is it safe to say that the crash is caused by closure #3 in closure #1 in closure #2 in loadBadges()?
In this case you can set exception breakpoints
here
and then here (in Exceptions -> All)

iphone app with multiple AVAudioPlayer crashes on iOS 6 upon interruption

I have an app that uses multiple AVAudioPlayer objects to play music. On iOS6, this app crashes when it is interrupted by a incoming phone call. The problem does not occur on iOS 4.3, 5.0 or 5.1. When the app crashes, the following stacktrace was seen.
(lldb) thread backtrace
* thread #1: tid = 0x2403, 0x3b905e64 libsystem_c.dylibpthread_mutex_lock + 388, stop reason = instruction step over
frame #0: 0x3b905e64 libsystem_c.dylibpthread_mutex_lock + 388
frame #1: 0x3299bd18 AVFoundationAVAudioPlayerCpp::sessionPropertyListener(unsigned long, unsigned long, void const*) + 124
frame #2: 0x33200b32 AudioToolboxAudioSessionPropertyListeners::CallPropertyListenersImp(unsigned long, unsigned long, void const*) + 170
frame #3: 0x332008cc AudioToolboxAudioSessionPropertyListeners::CallPropertyListeners(unsigned long, unsigned long, void const*) + 244
frame #4: 0x332b4afc AudioToolboxASCallbackReceiver_AudioSessionInterruptionListenerMessage + 184
frame #5: 0x33389dde AudioToolbox_XAudioSessionInterruptionListenerMessage + 70
frame #6: 0x3320058a AudioToolboxmshMIGPerform + 382
frame #7: 0x337a33e6 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #8: 0x337a338a CoreFoundation__CFRunLoopDoSource1 + 138
frame #9: 0x337a220e CoreFoundation__CFRunLoopRun + 1382
frame #10: 0x3371523c CoreFoundationCFRunLoopRunSpecific + 356
frame #11: 0x337150c8 CoreFoundationCFRunLoopRunInMode + 104
frame #12: 0x372f433a GraphicsServicesGSEventRunModal + 74
frame #13: 0x356312b8 UIKit`UIApplicationMain + 1120
I have added applicationWillResignActive and this does not get called when the crash occurs. I have also added my app delegate as a delegate to the AVAudioPlayer objects and implemented the audioPlayerBeginInterruption method. This method also does not get called when the crash occurs. If I use only 1 or 2 AVAudioPlayer objects, the crash goes away. The crash occurs with 3 more AVAudioPlayer objects, although only 2 of them are playing at a given time and the remaining have been stopped.
Has anyone seen this kind of problem or have any tips?
Thanks.

Calling FBSession.activeSession as instructed to in tutorial, results in NSException

I am trying to enable Facebook login in my iphone app.
I am following the instructions on this page:
https://developers.facebook.com/docs/howtos/login-with-facebook-using-ios-sdk/#step4
I have followed the instructions in Step #4 (Logging in to Facebook), but my code crashes when I run it.
This is my method that is causing the crash:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// We need to properly handle activation of the application with regards to Facebook Login
// (e.g., returning from iOS 6.0 Login Dialog or from fast app switching).
NSLog(#"here 1");
NSLog(#"active session: %#",FBSession.activeSession);
[FBSession.activeSession handleDidBecomeActive];
NSLog(#"here 2");
}
And here is my stack trace at the time of the crash (app name replaced with XXX):
2013-02-11 17:31:17.956 TRIO[9426:907] here 1
* thread #1: tid = 0x2503, 0x324d9960 libobjc.A.dylib`objc_exception_throw, stop reason = breakpoint 1.1
frame #0: 0x324d9960 libobjc.A.dylib`objc_exception_throw
frame #1: 0x3161af98 CoreFoundation`-[NSException raise] + 8
frame #2: 0x0009f7cc XXX`-[FBSession initWithAppID:permissions:defaultAudience:urlSchemeSuffix:tokenCacheStrategy:] + 240 at FBSession.m:236
frame #3: 0x0009f6d6 XXX`-[FBSession initWithAppID:permissions:urlSchemeSuffix:tokenCacheStrategy:] + 46 at FBSession.m:208
frame #4: 0x0009f680 XXX`-[FBSession init] + 32 at FBSession.m:191
frame #5: 0x000a061a XXX`+[FBSession activeSession] + 62 at FBSession.m:568
frame #6: 0x00073c4e XXX`-[AppDelegate applicationDidBecomeActive:] + 66 at AppDelegate.m:118
frame #7: 0x38e3bae2 UIKit`-[UIApplication _stopDeactivatingForReason:] + 342
frame #8: 0x38e219b8 UIKit`-[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 1072
frame #9: 0x38dc9c38 UIKit`-[UIApplication handleEvent:withNewEvent:] + 1004
frame #10: 0x38dc96cc UIKit`-[UIApplication sendEvent:] + 72
frame #11: 0x38dc911a UIKit`_UIApplicationHandleEvent + 6154
frame #12: 0x393605a2 GraphicsServices`_PurpleEventCallback + 590
frame #13: 0x393601d2 GraphicsServices`PurpleEventCallback + 34
frame #14: 0x315f0172 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 34
frame #15: 0x315f0116 CoreFoundation`__CFRunLoopDoSource1 + 138
frame #16: 0x315eef98 CoreFoundation`__CFRunLoopRun + 1384
frame #17: 0x31561ebc CoreFoundation`CFRunLoopRunSpecific + 356
frame #18: 0x31561d48 CoreFoundation`CFRunLoopRunInMode + 104
frame #19: 0x38e2047c UIKit`-[UIApplication _run] + 668
frame #20: 0x38e1d2f8 UIKit`UIApplicationMain + 1120
frame #21: 0x00073748 XXX`main + 96 at main.m:16
When I run the Facebook sample code, they work fine, and I believe I've added all the required frameworks.
Thanks.
I had the same error as above and it was because I did not add my own FacebookAppID along with the "URL types" key to my project's info.plist

Crash when save a photo

I have a strange crash when I save a UIImage into camera roll.
I Use this code:
UIImageWriteToSavedPhotosAlbum (_originalImage, self, #selector(photoSaved:didFinishSavingWithError:contextInfo:), nil);
-(void)photoSaved:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo {
if(!error){
NSLog(#"Photo saved to library!");
} else{
NSLog(#"Saving failed :(");
}
}
This is the Log:
2012-11-10 20:43:29.868 MyApp[5012:1a303] Photo saved to library!
This is the BT:
(lldb) bt
* thread #1: tid = 0x1f03, 0x024e509b libobjc.A.dylib`objc_msgSend + 15, stop reason = EXC_BAD_ACCESS (code=1, address=0x3094a576)
frame #0: 0x024e509b libobjc.A.dylib`objc_msgSend + 15
frame #1: 0x01b84a8b PhotoLibrary`-[PLUILibraryViewController updateNavigationItemButtons] + 216
frame #2: 0x01b6f054 PhotoLibrary`-[PLLibraryViewController(OverridePoints) updateInterfaceForHasContentChange] + 867
frame #3: 0x01c3c228 PhotoLibrary`-[PLAbstractLibraryViewController _updateHasContent] + 295
frame #4: 0x01c3c7d0 PhotoLibrary`-[PLAbstractLibraryViewController _updateAlbumsWithNotification:] + 681
frame #5: 0x01c3b870 PhotoLibrary`-[PLAbstractLibraryViewController albumListDidChange:] + 272
frame #6: 0x01b84c5b PhotoLibrary`-[PLUILibraryViewController albumListDidChange:] + 236
frame #7: 0x01525a29 Foundation`__57-[NSNotificationCenter addObserver:selector:name:object:]_block_invoke_0 + 40
frame #8: 0x0267d855 CoreFoundation`___CFXNotificationPost_block_invoke_0 + 85
frame #9: 0x0267d778 CoreFoundation`_CFXNotificationPost + 1976
frame #10: 0x0146a234 Foundation`-[NSNotificationCenter postNotification:] + 121
frame #11: 0x02d217a4 PhotoLibraryServices`-[PLChangeNotificationCenter _postEnqueuedNotifications] + 425
frame #12: 0x02d1f771 PhotoLibraryServices`-[PLChangeNotificationCenter _sendNotificationsForSplitChanges] + 307
frame #13: 0x02d23614 PhotoLibraryServices`-[PLChangeNotificationCenter managedObjectContext:didProcessRemoteContextSave:usingObjectIDs:] + 56
frame #14: 0x02d017cc PhotoLibraryServices`-[PLSharedManagedObjectContext _mergeChangesFromDidSaveDictionary:usingObjectIDs:] + 229
frame #15: 0x03edfd2f CoreData`__+[NSManagedObjectContext(_NSCoreDataSPI) _mergeChangesFromRemoteContextSave:intoContexts:]_block_invoke_4 + 159
frame #16: 0x03e67d03 CoreData`developerSubmittedBlockToNSManagedObjectContextPerform + 99
frame #17: 0x01af18d9 libdispatch.dylib`_dispatch_barrier_sync_f_slow_invoke + 93
frame #18: 0x01af2509 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 353
frame #19: 0x025e9803 CoreFoundation`__CFRunLoopRun + 2003
frame #20: 0x025e8d84 CoreFoundation`CFRunLoopRunSpecific + 212
frame #21: 0x025e8c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #22: 0x02a2d7d8 GraphicsServices`GSEventRunModal + 190
frame #23: 0x02a2d88a GraphicsServices`GSEventRun + 103
frame #24: 0x00b63626 UIKit`UIApplicationMain + 1163
frame #25: 0x000026ca MyApp`main + 170 at main.m:16
Full disclosure: I hope this makes sense as I'm pretty new to Objective-C, but I recently had a similar problem. I found out that my image was not being retained when I called the didFinishSavingWithError:contextInfo: method after selecting an image from the Camera Roll. What worked for me was adding the withObject: argument to my method call, as shown here:
[self performSelector:#selector(image:didFinishSavingWithError:contextInfo:) withObject:_originalImage];
This way, the image was retained when the didFinishSavgngWithError:contextInfo: method was called where previously it was not. Again, I'm new to Objective-C but I hope that helps...or at least points you in the right direction. What would also be helpful is if you could tell me at what point your app crashes (i.e. when you call the imagePicker, when you select an image from the camera roll, etc.).

xcode: can't show the exact line of the fault

I am keep seeing such errors but the xcode never shows the line that the error actually happened on, how to set the xcode to show the fault line directly? Till now it just point to the main function.
2012-06-27 21:46:33.513 Chapeng[838:f803] -[SendGiftViewController giftButtonClicked]: unrecognized selector sent to instance 0x6e392a0
The backtrace:
(lldb) bt
* thread #1: tid = 0x1f03, 0x92f359c6 libsystem_kernel.dylib`__pthread_kill + 10, stop reason = signal SIGABRT
frame #0: 0x92f359c6 libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x916e6f78 libsystem_c.dylib`pthread_kill + 106
frame #2: 0x916d7bdd libsystem_c.dylib`abort + 167
frame #3: 0x01e38e78 libc++abi.dylib`_Unwind_DeleteException
frame #4: 0x01e3689e libc++abi.dylib`_ZL17default_terminatev + 34
frame #5: 0x01c94f17 libobjc.A.dylib`_objc_terminate + 94
frame #6: 0x01e368de libc++abi.dylib`_ZL19safe_handler_callerPFvvE + 13
frame #7: 0x01e36946 libc++abi.dylib`std::terminate() + 23
frame #8: 0x01e37b3e libc++abi.dylib`__cxa_rethrow + 83
frame #9: 0x01c94e15 libobjc.A.dylib`objc_exception_rethrow + 47
frame #10: 0x01612de0 CoreFoundation`CFRunLoopRunSpecific + 304
frame #11: 0x01612c9b CoreFoundation`CFRunLoopRunInMode + 123
frame #12: 0x0222b7d8 GraphicsServices`GSEventRunModal + 190
frame #13: 0x0222b88a GraphicsServices`GSEventRun + 103
frame #14: 0x0061b626 UIKit`UIApplicationMain + 1163
frame #15: 0x00001ec2 Chapeng`main + 130 at main.m:16
(lldb)
Add a symbolic breakpoint on objc-exception-throw. A tutorial on this is available here. This should make GDB / LLDB stop execution when an unrecognized selector is sent.
EDIT: after reading your backtrace, it appears you have an invalid IB connection. Check all of your buttons on your view controller, and make sure they are linked to a proper selector.
Press cmd+shift+f and paste giftButtonClicked. It will show the list of string in your project find where you have called this method from any class. This error will raise because giftButtonClicked method was not recognizable at the time of calling