我想制作一个每小时播放声音的程序,但我卡住了。我需要一些帮助来解决问题,问题是我不知道如何告诉程序每小时播放声音。我正在尝试一些比较(我将日期设置为整数并与其他整数进行比较),但这似乎有效......有人可以帮忙吗?(例如:我希望 NSDate 播放我 az 13:00 的声音)很多谢谢
问问题
277 次
6 回答
2
NSTimer
is ok if you know the iOS app will be in the foreground when the timer expires. However to be more robust you'd need to use 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];
声音文件必须是您的应用程序主包的一部分,但您不能使用任意声音文件。
于 2011-04-19T14:28:22.227 回答
0
Use NSTimer.
于 2011-04-19T13:55:36.023 回答
0
你需要的是一个:NSTimer
本教程可以提供帮助。
于 2011-04-19T13:56:50.610 回答
0
You could use NSTimer
.
Setup NSTimer
NSTimer *timer = [[NSTimer alloc]initWithFireDate:<your_start_date>
interval:(60 * 60)
target:self
selector:@selector(timerHandler:)
userInfo:nil
repeats:YES];
and write your handler..
-(void)timerHandler:(NSTimer*)timer{
//play your sound here..
}
于 2011-04-19T13:59:10.563 回答
0
Try this..
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 回答