0

ボタンをクリックして簡単な音を鳴らそうと何時間も努力してきましたが、出来ませんでした。いくつかのチュートリアルを試した後、私はこのリンクの1つをたどりました:

http://www.mybringback.com/tutorial-series/1126/xcode-4-tutorial-ios-ipad-iphone-20-playing-sound-with-button/

これは.hファイルです:

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface soundTestViewController : UIViewController{

}
-(IBAction) playSound;

@end

これは.mファイルです:

#import "soundTestViewController.h"

@implementation soundTestViewController
-(IBAction) playSound{
    CFBundleRef mainBundle=CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"mysound", CFSTR("mp3"), NULL);
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end 

ただし、ビルド結果にはエラーがあります。

Build soundTest of project soundTest with configuration Debug

Ld build/Debug-iphonesimulator/soundTest.app/soundTest normal i386
cd /Users/joegeneric/Documents/soundTest
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk -L/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator -F/Users/joegeneric/Documents/soundTest -filelist /Users/joegeneric/Documents/soundTest/build/soundTest.build/Debug-iphonesimulator/soundTest.build/Objects-normal/i386/soundTest.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -framework AVFoundation -framework AudioToolbox -o /Users/joegeneric/Documents/soundTest/build/Debug-iphonesimulator/soundTest.app/soundTest

ld: warning: in /Users/joegeneric/Documents/soundTest/AVFoundation.framework/AVFoundation, missing required architecture i386 in file
ld: warning: in /Users/joegeneric/Documents/soundTest/AudioToolbox.framework/AudioToolbox, missing required architecture i386 in file
Undefined symbols:
  "_AudioServicesPlaySystemSound", referenced from:
      -[soundTestViewController playSound] in soundTestViewController.o
  "_AudioServicesCreateSystemSoundID", referenced from:
      -[soundTestViewController playSound] in soundTestViewController.o
ld: symbol(s) not found

ここに画像の説明を入力してください 私が間違ったことや、iPhone SDKでサウンドを再生するためのその他の簡単なチュートリアルを教えていただけますか?

4

2 に答える 2

2

【massimobioの正解に加えて】

あなたが提供したチュートリアルのリンクは、iOS 用の Xcode 4 について言及していますが、ビルド結果の「setenv MACOSX_DEPLOYMENT_TARGET 10.6」行は、展開ターゲットが Mac であることを示しています。

Project Build Architecture を iOS に変更し、ターゲットが OSX ではなく IOS であることを確認する必要があります。

たとえば、ビルド アーキテクチャを変更するには、プロジェクトをクリックし、[ビルド設定] を選択して Base SDK を表示します。ここに画像の説明を入力

また、IBAction に送信者がありません。コントローラーのヘッダー ファイルで次のように宣言する必要があります。

-(IBAction) playSound:(id)sender;

コントローラーの .m ファイルに次のように実装されます。

-(IBAction) playSound:(id)sender {
  // your code here
}

また、コントロールとドラッグを使用してコード内の IBAction を XIB にリンクし、アクションとターゲットのペアを作成することを忘れないでください。

サウンドを再生する最も簡単なデモは SysSound です。Xcode のドキュメントを検索するか、サンプル コードの下にある Apple Developer Web サイトから入手できます。

于 2012-07-08T18:07:30.693 に答える
1

AudioToolbox フレームワークをターゲットに追加し、これをコードにインポートしましたか?

#import <AudioToolbox/AudioToolbox.h>
于 2012-07-08T17:54:34.163 に答える