iphone - UILocalNotification 每分钟重复一次

标签 iphone ios ios5 uilocalnotification localnotification

我想每分钟发送一次本地通知,这是我正在使用的代码:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

    UILocalNotification *notif = [[UILocalNotification alloc] init];

    if (notif == nil) {
        return;
    }

    notif.timeZone = [NSTimeZone defaultTimeZone];

    notif.alertBody = @"Test notification!";
    notif.alertAction = @"View";
    notif.soundName = UILocalNotificationDefaultSoundName;
    notif.applicationIconBadgeNumber += 1;

    notif.repeatInterval = NSMinuteCalendarUnit;

    [[UIApplication sharedApplication] scheduleLocalNotification:notif];

通知只开始一次,永远不会重复。我哪里弄错了?

最佳答案

您必须为您的通知设置一个fireDate,否则它不会重复而是立即触发。

The fire date is interpreted according to the value specified for timeZone. If the specified value is nil or is a date in the past, the notification is delivered immediately.

关于iphone - UILocalNotification 每分钟重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13490573/

相关文章:

iphone - 这是UIKit错误吗?

objective-c - plist 在字典中写入数据

ios - Xcode 8 中的自适应布局

objective-c - EasyTableView 的单元格选择问题

iphone - 在ios5中访问相机 View 并捕获图像使用哪个框架?

iphone - 如何在 iPhone 应用程序的 UIImagePickerView 中隐藏相机控件?

ios - 显示键盘时,Admob 广告不会出现在 UITableView 的页脚中

iphone - iOS 打印不允许 UIPrintInteractionController 出现

ios - IOS6 中的 NSDictionary 问题?

ios - SwiftUI 表情符号键盘隐藏在 ScrollView 中