2012-04-08 68 views
1

我更新到OS X Lion 10.7.3和Xcode 4.3.2。我無法使用以下代碼在iPhone模擬器或iPhone設備上播放聲音。我可以在Snow Leopard和Xcode 4.2上使用相同的代碼播放聲音。我不知道爲什麼我無法聽到4.3.2中的聲音。任何人都可以幫忙嗎?Xcode 4.3.2中的聲音

.h文件中

#import <UIKit/UIKit.h> 
#import <AudioToolbox/AudioToolbox.h> 


@interface soundViewController : UIViewController { 
} 

-(IBAction)playSounds:(id)sender; 

@end 

.m文件

-(IBAction)playSounds:(id)sender { 

CFBundleRef mainBundle = CFBundleGetMainBundle(); 
CFURLRef soundFileURLRef; 
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"E", CFSTR("caf"), NULL); 
UInt32 soundID; 
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
AudioServicesPlaySystemSound(soundID); 
} 
+0

是'soundFileURLRef'' NULL'?你爲目標的資源添加了「E.caf」嗎? – 2012-04-08 07:28:10

+0

另請參閱此[類似問題](http://stackoverflow.com/questions/7856896/couldnt-play-system-sound-after-switching-to-ios-5)。 – 2012-04-08 07:29:48

+0

我把 NSError *錯誤 的NSLog(@ 「%@」,錯誤USERINFO) 並返回null兩個,但在iMac上播放 E.caf是我的目標資源。 – Kinematic 2012-04-08 07:34:36

回答

0

的XCode 4.3,有時從複製的資源列表沒有理由排除文件。驗證文件是否包含在您的目標中。即使添加它,有時也不會成爲目標的資源。單擊該文件並選擇屬性檢查器的最左側選項卡,並確保在「目標成員」部分中選中了目標旁邊的複選框。