3

我正在开发一个闹钟应用程序

通过通知中心的警报+音乐频道

如果 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];
}
4

2 回答 2

0

我们可以覆盖静音开关来播放声音。

在这种情况下,这取决于 iOS 在触发通知时如何播放声音。

你在设备上检查过这个吗?

于 2013-03-08T12:39:11.203 回答
0

你应该看看AudioSession 类别

AVAudioSessionCategoryPlayback 应该可以解决问题。

于 2013-04-17T07:18:29.627 回答