我正在制作一个闹钟App
警报+音乐频道通过通知中心
如果iPhone设置为静音模式,它将不会激活
许多用户要求警报覆盖静音模式
这可能吗?
干杯!
(void)addLocalNotification:(myAlarmData *)ma WeekDay:(int)mweekday
{
UILocalNotification *noti = [[UILocalNotification alloc] init];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now = [NSDate date];
NSDateComponents *dcom = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit |NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate:now];
[dcom setWeekday:mweekday];
[dcom setHour:ma.mHour];
[dcom setMinute:ma.mMinute];
[dcom setSecond:0];
NSDate *fireDate = [gregorian dateFromComponents:dcom];
noti.fireDate = fireDate;
noti.timeZone = [NSTimeZone localTimeZone];
noti.alertBody = [NSString stringWithFormat:@"Wake up %@!", [GlobalData gSettings].name];
noti.soundName = [NSString stringWithFormat:@"%@.caf", ma.soundName];
noti.alertAction = @"OK";
noti.repeatInterval = NSWeekCalendarUnit;
noti.userInfo = [[[NSDictionary alloc] initWithObjectsAndKeys:
ma.mid, @"mid",
[NSString stringWithFormat:@"%d", mweekday], @"day",
ma.soundName, @"sound",
[NSString stringWithFormat:@"%d", ma.snooze], @"snooze",
ma.title, @"title",
@"Close", @"action",
@"real", @"more",
nil] autorelease];
[[UIApplication sharedApplication] scheduleLocalNotification:noti];
[noti release];
[gregorian release];
}
答案 0 :(得分:0)
我们可以覆盖静音开关来播放声音。
在这种情况下,它取决于iOS在触发通知时如何设置播放声音。
您是否已在设备上查看此内容。?
答案 1 :(得分:0)
你应该看看AudioSession categories。
AVAudioSessionCategoryPlayback应该可以解决问题。