3

I used these codes

- (void)viewDidLoad
{
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
AudioSessionAddPropertyListener (
                                 kAudioSessionProperty_AudioRouteChange,
                                 audioRouteChangeListenerCallback,
                                 self
                                 );
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
}

and

void audioRouteChangeListenerCallback (void *inUserData, AudioSessionPropertyID inPropertyID, UInt32 inPropertyValueSize, const void *inPropertyValue ) {
    // ensure that this callback was invoked for a route change
    if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return;


    {
        // Determines the reason for the route change, to ensure that it is not
        //      because of a category change.
        CFDictionaryRef routeChangeDictionary = (CFDictionaryRef)inPropertyValue;

        CFNumberRef routeChangeReasonRef = (CFNumberRef)CFDictionaryGetValue (routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) );
        SInt32 routeChangeReason;
        CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);

        if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) {

            //Handle Headset Unplugged
        } else if (routeChangeReason == kAudioSessionRouteChangeReason_NewDeviceAvailable) {
            //Handle Headset plugged in
        }

    }
}

to detect if audio jack is plugged in or out in my project but I end up with this error

Undefined symbols for architecture armv7:
  "_AVAudioSessionCategoryAmbient", referenced from:
      -[ViewController viewDidLoad] in ViewController.o
  "_OBJC_CLASS_$_AVAudioSession", referenced from:
      objc-class-ref in ViewController.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

So what is the issue in it? I'm a beginner in ios any help will be appreciated.

1 Answer 1

18

You have miss to add AudioToolBox.Frameworks to project file. Double check with your project file setting..

Update Actually missed AVFoundation.Frameworks to add in the build phase of project.

Update 2
The trailing s has been removed. Now it is AudioToolBox.Framework and AVFoundation.Framework

3
  • 2
    Did you import this one import<AudioToolbox/AudioToolbox.h> and did you add AVFoundation.Frameworks?
    – Mani
    Apr 23, 2013 at 6:20
  • Yes I imported <AudioToolbox/AudioToolbox.h>
    – Dolo
    Apr 23, 2013 at 6:22
  • Yes AVFoundation.Frameworks not added in build phase now I added manually it works thanks
    – Dolo
    Apr 23, 2013 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.