I have a UITableView with multiple cells that can contain play buttons. Each play button has a UITapGetsureRecognizer that invokes a NSURLConnection to download the audio file. The NSURLConnection is declared inside my AudioPlayer class which extends an NSObject . Right now, when a user pressed play, we begin downloading. Upon the download completing, we play the audio. If the user tries to press the play button of another audio file while a download is in progress, we successfully cancel the NSURLConnection, set the connection to nil, and open a new connection for the requested audio file. This works great.
I have a problem when the user presses play, the download begins, and then the user pressed the back button (on a NavigationBarOverlay). This causes the app to freeze. I have tried to add code inside of UITableView's viewWillDisappear with no luck. I have tried to override the dealloc method of the AudioPlayer function - no luck. I have changed the implementation of the AudioPlayer class to be initiated with a NSURLConnection pointer (instead of being responsible for alloc'ing the connection, give the responsibility to the UITableView)
Here is some examples of what I've tried:
inside UITableView
-(void) viewWillDisappear:(BOOL)animated {
[audioConnection cancel];
[messagePlayer stop];
}
and inside of AudioPlayer Object
-(void) dealloc {
[self.audioConnection cancel];
}
When I pause the debugger when the freeze occurs the call stack looks like this: Thread 1
Queue: com.apple.main-thread
0 semaphore_wait_trap
.....................................................
4 +[NSURLConnection sendSynchronousRequest:returningResponse:error:]
5 +[Utilities serviceAvailable]
6 -[MessageViewController backButtonPressed] //Note: this is my UITableView
7 -[ViewController backButtonPress]
8 -[NavigationBarOverLayView backButtonPressed:]
9 _UIGestureReconginzerSendActions
Does anybody have any ideas? Does anybody have any ideas why NSURL sendSynchronousRequest is in the call stack. I thought when you initiated the connection like so:
self.audioConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
it would asynchronously download the file. Am I wrong?
Thank you. Please let me know if you need any more information.
EDIT: It appears this 'freeze' happens for a little more than 1 minute on iOS 7.1 iPhone 4 retina simulator. Then it resumes normal functionality. To be a bit more descriptive, when a user taps the back button, there is a color change on the button to indicate it has been pressed. During the freeze, this button appears to be "pressed" the entire time.