【问题标题】:iPhone - UILocalNotification as alarmiPhone - UILocalNotification 作为警报
【发布时间】:2011-07-14 16:05:18
【问题描述】:

即使我的 iPhone 应用程序在后台,我如何使用 UILocalNotification 在每天晚上 8 点显示我的闹钟?

【问题讨论】:

    标签: iphone alarm uilocalnotification


    【解决方案1】:

    fireDate 设置为晚上8 点,将repeatInterval 设置为NSDayCalendarUnit,并使用[[UIApplication sharedApplication] scheduleLocalNotification: myNotification]; 安排警报

    【讨论】:

    • 即使手机设置为静音模式,是否可以强制 UILocalNotification 发出声音?
    • 即使应用程序不在后台运行也能正常工作吗?
    • @AnthonyChan UILocalNotification 仅在手机未处于静音模式时才会发出声音。
    【解决方案2】:

    dasdom 答案是正确的。只是想补充一点,如果您的设备处于静音模式,警报将不会发出声音。这是 Apple 对 UILocalNotification 的限制。

    【讨论】:

    • 应该如此!当我希望手机静音时,我不希望任何应用多管闲事!
    【解决方案3】:
    UILocalNotification *localNotification =[[UILocalNotification alloc]init];
    
     NSCalendar *calendar=[NSCalendar currentCalendar];
        [calendar setTimeZone:[NSTimeZone defaultTimeZone]];
    
        unsigned currentFlag=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSWeekdayCalendarUnit;
    
        NSDateComponents *comp=[calendar components:currentFlag fromDate:[NSDate date]];
    
        comp.hour=8;
        comp.minute=0;
        comp.second=0;
    
        NSDate *date=[[calendar dateFromComponents:comp]dateByAddingTimeInterval:0];
    
        if (localNotification==nil) {
            return;
        }
    
        localNotification.fireDate=date;
        localNotification.timeZone=[NSTimeZone defaultTimeZone];
        localNotification.repeatCalendar=[NSCalendar currentCalendar];
    
        localNotification.alertBody=@"Good Morning dude..!";
    
        localNotification.alertAction=@"Snooze";
    
        localNotification.repeatInterval=NSDayCalendarUnit;
    
        localNotification.soundName=@"goodmorning.caf";
    
    [[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
    

    我希望这会对你有所帮助...!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      • 1970-01-01
      相关资源
      最近更新 更多