Search code examples
xcodeios7

setDelegate deprecated in iOS 6


I am trying to get this sample code running with iOS 7.0 but I am running into some warnings because of deprecated code. The sample code provided here hasn't been updated in 3 years. Here is the solution I found which does make sense to me but I am having trouble implementing in the sample code so it will run inside the iOS simulator.

AVAudioSession* session = [AVAudioSession sharedInstance];
session.delegate = self;// <-------- DEPRECATED IN IOS 6.0

To silence the warning change those 2 lines to this:

[[AVAudioSession sharedInstance] setActive:YES error:nil];

Someone else suggested

[AVAudioSession sharedInstance];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interruption:) name:AVAudioSessionInterruptionNotification object:nil];

The above solution is a quick fix but I want to get the program running correctly

But all this makes me wonder how do I say function call setPreferredHardwareSampleRate into something that is not deprecated

[mySession setPreferredHardwareSampleRate: graphSampleRate
                                    error: &audioSessionError];

enter image description here


Solution

  • Generally, when a method is deprecated, the headers/documentation are updated with suggestions about what to do instead. Looks like the documentation in this case suggests -setPreferredSampleRate:error: as an alternative.