gpt4 book ai didi

ios - iOS 闹钟

转载 作者:行者123 更新时间:2023-12-01 16:48:03 30 4
gpt4 key购买 nike

我尝试在 Xcode 4.6.3 - http://vimeo.com/29824336 下重写以下教程

但我有一个问题,在 24:00 左右我的代码没有发出警报:

-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = fireDate;
notification.alertBody = @"Time to wake up!";
notification.soundName = @"SNSD-Oh.caf";
NSLog(@"Ring Ring Ring!");

[[UIApplication sharedApplication] scheduleLocalNotification: notification];
}

- (IBAction) alarmSetButtonTapped:(id)sender
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;

NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date];
NSLog(@"Alarm Set Button tapped: %@", dateTimeString);

[self scheduleLocalNotificationWithDate: dateTimePicker.date];
}

我做错什么了?

最佳答案

通知触发时,您的应用不得在前台运行。

如果要在前台播放声音,可以使用 UIAlertView 的组合和“AvAudioPlayer”。

您可以在
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification AppDelegate.m 的委托(delegate)方法.

欢迎进一步询问。

关于ios - iOS 闹钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18412651/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com