2

これらのコードを使用しました

- (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];
}

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
        }

    }
}

プロジェクトでオーディオジャックがプラグインまたはプラグアウトされているかどうかを検出しますが、このエラーが発生します

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)

それで、その問題は何ですか?私はiosの初心者で、助けていただければ幸いです。

4

1 に答える 1

17

AudioToolBox.Frameworksプロジェクトファイルに追加するのを逃しました。プロジェクトファイルの設定を再確認してください。

更新 実際には、プロジェクトのビルド段階で追加する AVFoundation.Frameworks を見逃していました。

更新 2
末尾sが削除されました。今はそうですAudioToolBox.Frameworkし、AVFoundation.Framework

于 2013-04-23T06:13:09.267 に答える