Ios 定时启动目标-c
我想制作一个每小时播放声音的程序,但是我被卡住了。我需要一些帮助来解决这个问题,问题是我不知道如何告诉程序每小时播放声音。我尝试进行一些比较(我将日期设置为一个整数,并与另一个整数进行比较),但这个方法似乎有效…有人能帮忙吗?(例如:我希望NSDate为我播放az 13:00的声音)许多thanx使用 请参阅。使用Ios 定时启动目标-c,ios,objective-c,cocoa-touch,nsdate,timed,Ios,Objective C,Cocoa Touch,Nsdate,Timed,我想制作一个每小时播放声音的程序,但是我被卡住了。我需要一些帮助来解决这个问题,问题是我不知道如何告诉程序每小时播放声音。我尝试进行一些比较(我将日期设置为一个整数,并与另一个整数进行比较),但这个方法似乎有效…有人能帮忙吗?(例如:我希望NSDate为我播放az 13:00的声音)许多thanx使用 请参阅。使用 请参阅。您需要的是:n计时器 这可能会有所帮助。您需要的是:n计时器 这可能会有帮助。您可以使用NSTimer 设置NSTimer NSTimer *timer = [[NSTime
请参阅。您需要的是:n计时器
这可能会有所帮助。您需要的是:n计时器
这可能会有帮助。您可以使用
NSTimer
设置NSTimer
NSTimer *timer = [[NSTimer alloc]initWithFireDate:<your_start_date>
interval:(60 * 60)
target:self
selector:@selector(timerHandler:)
userInfo:nil
repeats:YES];
您可以使用
NSTimer
设置NSTimer
NSTimer *timer = [[NSTimer alloc]initWithFireDate:<your_start_date>
interval:(60 * 60)
target:self
selector:@selector(timerHandler:)
userInfo:nil
repeats:YES];
试试这个
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(myTimerMethod:) userInfo:nil repeats:YES];
-(void)myTimerMethod
{
//Play an Alarm
}
试试这个
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self selector:@selector(myTimerMethod:) userInfo:nil repeats:YES];
-(void)myTimerMethod
{
//Play an Alarm
}
NSTimer
如果您知道计时器过期时iOS应用程序将位于前台,则可以。但是,为了更健壮,您需要使用。NSTimer
如果您知道计时器过期时iOS应用程序将位于前台,则可以。但是,为了更健壮,您需要使用。如果您想在特定时间播放声音如果应用程序未在前台运行,您将不得不使用通知:
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];
UILocalNotification*localNotif=[[UILocalNotification alloc]init];
localNotif.fireDate=;
localNotif.repeatInterval=NSHourCalendarUnit;
localNotif.soundName=@“soundFile.caf”;
localNotif.timeZone=[NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
[localNotif发布];
但声音文件必须是应用程序主捆绑包的一部分,不能使用任意声音文件
如果您希望在指定时间播放声音,而应用程序不在前台运行,则必须使用通知:
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];
UILocalNotification*localNotif=[[UILocalNotification alloc]init];
localNotif.fireDate=;
localNotif.repeatInterval=NSHourCalendarUnit;
localNotif.soundName=@“soundFile.caf”;
localNotif.timeZone=[NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
[localNotif发布];
但声音文件必须是应用程序主捆绑包的一部分,不能使用任意声音文件