2013-04-23 29 views
0

使用AVAudioSession我使用這些代碼錯誤而在IOS

- (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任何幫助將不勝感激。

回答

10

您無法將AudioToolBox.Frameworks添加至項目文件。仔細檢查你的項目文件設置..

更新 實際上錯過AVFoundation.Frameworks添加到項目的構建階段。

+0

我添加了但仍然有錯誤 – Dolo 2013-04-23 06:18:10

+2

您是否已經導入了這個'import '並添加了'AVFoundation.Frameworks'? – Mani 2013-04-23 06:20:22

+0

是的,我輸入了 Dolo 2013-04-23 06:22:30