0

毎時間サウンドを再生するプログラムを作成したいのですが、立ち往生しています。問題を解決するには助けが必要です。その問題は、プログラムに毎時間サウンドを再生するように指示する方法がわからないことです。比較します (日付を整数に設定し、他の整数と比較します)、しかし、これは機能していないようです...誰か助けてくれますか? (例: NSDate が az 13:00 の音を再生してほしい)ありがとう

4

6 に答える 6

2

NSTimerタイマーが切れたときに iOS アプリがフォアグラウンドになることがわかっている場合は問題ありません。ただし、より堅牢にするには、local noficationsを使用する必要があります。

于 2011-04-19T13:59:44.947 に答える
1

アプリをフォアグラウンドで実行せずに、指定した時間にサウンドを再生したい場合は、通知を使用する必要があります。

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = <some hour in the future>;
localNotif.repeatInterval = NSHourCalendarUnit;
localNotif.soundName = @"soundFile.caf";
localNotif.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];

ただし、サウンド ファイルはアプリケーションのメイン バンドルの一部である必要があり、任意のサウンド ファイルを使用することはできません。

http://developer.apple.com/library/ios/#documentation/iphone/Reference/UILocalNotification_Class/Reference/Reference.html

于 2011-04-19T14:28:22.227 に答える
0

必要なものは次のとおりです: NSTimer

このチュートリアルが役立ちます。

于 2011-04-19T13:56:50.610 に答える
0

NSTimerを使用します。

タイマーの作成とスケジュールを参照してください。

于 2011-04-19T13:55:36.023 に答える
0

を使用できますNSTimer

設定NSTimer

NSTimer *timer = [[NSTimer alloc]initWithFireDate:<your_start_date> 
                     interval:(60 * 60)  
                     target:self 
                     selector:@selector(timerHandler:) 
                     userInfo:nil 
                     repeats:YES];

そしてあなたのハンドラを書いてください..

-(void)timerHandler:(NSTimer*)timer{
 //play your sound here..
}
于 2011-04-19T13:59:10.563 に答える
0

これを試して..

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(myTimerMethod:) userInfo:nil repeats:YES];

-(void)myTimerMethod
{
//Play an Alarm
}
于 2011-04-19T13:59:22.963 に答える