iPhone - UILocalNotification 作为警报

发布于 2024-11-19 23:31:09 字数 69 浏览 3 评论 0原文

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

Even when my iPhone application is in background, How can I use UILocalNotification to show my alram every day at 8.00 PM?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-11-26 23:31:09

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

Set the fireDate to 8.00 PM and set the repeatInterval to NSDayCalendarUnit and schedule the alert with [[UIApplication sharedApplication] scheduleLocalNotification: myNotification];

笑咖 2024-11-26 23:31:09

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

dasdom answer is correct. just wanted to add to it that the alarm will not make a sound if your device is in silent mode. It is a restriction from Apple for UILocalNotification.

初雪 2024-11-26 23:31:09
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];

我希望这能帮助你......!

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];

I hope this will help you...!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文