Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为循环中的某一天设置通知_Ios_Swift - Fatal编程技术网

Ios 为循环中的某一天设置通知

Ios 为循环中的某一天设置通知,ios,swift,Ios,Swift,我想显示本地通知,就像我在这里设置的一样,如下图所示: 当我单击“创建故事”按钮时,我会将故事的属性发送到通知 我的故事有如下特点: @NSManaged var remindeAtHour: Int @NSManaged var remindeAtMinute: Int @NSManaged var remindeAtDaysOfWeek: [Bool] // -> This means that from // Monday to Sunday, if it true, it is

我想显示本地通知,就像我在这里设置的一样,如下图所示:

当我单击“创建故事”按钮时,我会将故事的属性发送到通知

我的故事有如下特点:

@NSManaged var remindeAtHour: Int
@NSManaged var remindeAtMinute: Int
@NSManaged var remindeAtDaysOfWeek: [Bool] // -> This means that from
// Monday to Sunday, if it true, it is set, if it false, it not be set. 
这是我的提醒通知类代码:

import Foundation
import UIKit

class RemindNotification {

  var timerNotification = NSTimer()

  func notification(story: Story) {
    let timeInterval = NSTimeInterval(story.remindeAtHour * 3600 + story.remindeAtMinute * 60)
    let notification = UILocalNotification()
    notification.alertAction = "Title"
    notification.alertBody = "It's time to take a photo"
    notification.fireDate = NSDate(timeIntervalSinceNow: timeInterval)
    UIApplication.sharedApplication().scheduleLocalNotification(notification)
    timerNotification.invalidate()
  }
}
我已经用此代码显示了本地通知


但是我想在它上面设置日期,这样它就可以循环显示我设置的日期的通知。例如,我将时间设置为8:30,我选择某一天“周一、周三、周五、周日”,现在是周二12:35,所以在周三的8:30,它将显示通知,依此类推。。。下周的星期一,它将一次又一次地出现。如何做到这一点???

如apple文档中所述,您可以同时设置最多64个本地通知

Apple Doc说:一台设备上的每个应用程序都限制在64个预定的本地通知中。系统将丢弃超过此限制的计划通知,只保留最快发出的64个通知。定期通知被视为单个通知

解决方案

如果没有计划通知,则在用户打开应用程序后的5-6天内设置通知。使用以下方法查找计划通知,该方法返回所有计划通知的列表,并根据该列表计划下一次通知

NSArray *arrScheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications]
在应用程序启动时执行此操作

阅读更多关于

备选方案

安排一个日历事件。它允许您在任何时间点设置事件数。虽然它不与应用程序关联,但它会向您显示提醒。如果它满足您的要求,您可以选择它

更多详情