2011-04-19 11 views
0

私は、時間がたつにつれてサウンドを再生するプログラムを作りたいと思っています。私は問題を解決するためにいくつかの助けが必要です。その問題は、プログラムをサウンド再生する方法を知らないことですいくつかの比較(私は整数に日付を設定し、他の整数と比較)しようとしていますが、この呪文はうまくいくようです...誰かが助けることができますか?(例:NSDateが私をプレイしたい音az 13:00)たくさんの時間指定された開始目的-c

答えて

0

は何が必要です:このtutorialは助けることができるNSTimer

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.. 
} 
0

これを試してみてください..あなたは、iOSアプリはになります知っていれば

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

-(void)myTimerMethod 
{ 
//Play an Alarm 
} 
2

NSTimerはokですタイマーの期限が切れる前景。ただし、より堅牢にするにはlocal noficationsを使用する必要があります。

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]; 

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

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

関連する問題