gpt4 book ai didi

iPhone - 在应用程序处于后台时播放闹钟声音

转载 作者:搜寻专家 更新时间:2023-10-30 19:58:17 26 4
gpt4 key购买 nike

你知道如何在 iPhone 休眠时播放闹钟声音吗?喜欢 iPhone 中的内置时钟应用程序吗?

非常重要的编辑:
在 iPhone 的内置时钟应用程序中
播放闹钟声音时,如果用户将静音开关切换到静音(振动模式),
警报声仍在继续播放。

你知道怎么做吗?

最佳答案

此代码将帮助您在后台播放音乐:音乐的声音文件应该只有 30 秒通知支持 30 秒的声音文件,它应该在 bundle 文件夹中,如果它在文档文件夹中,那么你必须放置声音文件的路径

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
NSString *dateValueRemaining =[NSString stringWithFormat:@"23/08/2012 11:30:33"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
NSDate *dateRemaining = [dateFormat dateFromString:dateValueRemaining];
NSDate *pickerDate = dateRemaining;
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit
| NSMonthCalendarUnit
| NSDayCalendarUnit)
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit
| NSMinuteCalendarUnit
| NSSecondCalendarUnit)
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
NSLog(@"itemDate: %@", itemDate);
if (localNotif) {
[[UIApplication sharedApplication] cancelLocalNotification:localNotif];
}
localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil) {
return;
}
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = itemDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = @"Your Time is Over";
localNotif.alertAction = @"View";
//---THIS SONG FILE IN THE NSBUNDLE FOLDER---------//
localNotif.soundName = @"s1.mp3";
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

关于iPhone - 在应用程序处于后台时播放闹钟声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372800/

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