まず、私はObjective Cでかなり新しいです。特定の条件下で音を鳴らして振動させたいと思っています。私の iPhone 4 はミュートになっていません。大文字と小文字の区別を確認し、AVAudioPlay と SystemSound の両方を使用してファイルを再生しようとしましたが、バイブレーションも機能しません。AudioToobox と AVfoundation は .h にインポートされます。オーディオは、iOS シミュレーターで両方の方法で再生されます。
SystemSound を使用したコードは次のとおりです。
if (al == 1){
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef =CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Alarm", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);}
And with AVAudioPlayer:
if (al == 1) {NSString *path = [[NSBundle mainBundle] pathForResource:@"alarmtwo" ofType:@"wav"];
AVAudioPlayer *theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.numberOfLoops = 0;
theAudio.volume = 1.5;
[theAudio prepareToPlay];
[theAudio play];}
By the way, the variable al sets to 0 after it plays. Is my coding wrong to have the sound and vibrate work on the device itself? Is there a specific type of .wav file that needs to be played? Any help would be appreciated.