我已经搜索过了,我找到了UILocalNotification,但只有在应用程序不活动且我无法实现自定义声音和延后时它才有效。这是我的代码
UILocalNotification* alarm = [[UILocalNotification alloc] init];
alarm.fireDate = [myPicker date];
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.hasAction = YES;
alarm.alertAction = @"SNOOZE";
alarm.repeatInterval = 0;
alarm.soundName = @"Notification.aif";
alarm.alertBody = @"Alarm";
//[app scheduleLocalNotification:alarm];
[[UIApplication sharedApplication] scheduleLocalNotification:alarm];
非常感谢帮助。
答案 0 :(得分:1)
你的方法绝对正确。但我以为你忘记了UILocalNotification的一些事情。
UILocalNotification对象指定应用可以在特定日期和时间安排演示的通知。操作系统负责在预定时间发送本地通知; 应用程序不必为此而运行。
答案 1 :(得分:0)
谢谢,我已经使用UILocalNotification和我自己的声音名称在appReceiveLocalNotification中以另一种方式播放它,在didReceiveLocalNotification
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"Received notification");
// Play a sound and show an alert only if the application is active, to avoid doubly notifiying the user.
if ([application applicationState] == UIApplicationStateActive) {
NSLog(@"active");
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"alarm2" ofType:@"wav"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundURL, &_mySound);
AudioServicesPlaySystemSound(self.mySound);
}
}