Ios 如何定义用户在swift中注册后的第二天早上?

Ios 如何定义用户在swift中注册后的第二天早上?,ios,swift,Ios,Swift,我正在尝试在用户注册后的三个月内安排一些通知。不过,首先我需要定义注册后的第一个早晨。 你能帮我吗?安排一个本地通知 let localNotif = UILocalNotification() let calendar = NSCalendar.autoupdatingCurrentCalendar() let dateComps = NSDateComponents() dateComps.day = registrationDate.day dateComps.month = regis

我正在尝试在用户注册后的三个月内安排一些通知。不过,首先我需要定义注册后的第一个早晨。
你能帮我吗?

安排一个本地通知

let localNotif = UILocalNotification()
let calendar = NSCalendar.autoupdatingCurrentCalendar()
let dateComps = NSDateComponents()

dateComps.day = registrationDate.day
dateComps.month = registrationDate.month
dateComps.year = registrationDate.year
dateComps.hour = 9
dateComps.minute = 0

let itemDate = calendar.dateFromComponents(dateComps)

localNotif.fireDate = itemDate.dateByAddingTimeInterval(24.0 * 60.0 * 60.0)
localNotif.timeZone = NSTimeZone.defaultTimeZone()

localNotif.alertBody = "Good Morning new user!"
localNotif.alertAction = "View details"
localNotif.alertTitle = "Good morning"

localNotif.soundName = UILocalNotificationDefaultSoundName
localNotif.applicationIconBadgeNumber = 1

UIApplication.sharedApplication().scheduleLocalNotification(localNotif)

请表明您已经准备好了-编写一些代码并发布。从服务器获取注册的时间戳,将其转换为NSDate。将其拆分为多个组件。添加三个月到一个月的组件。从这些组件创建新的日期。为该日期安排一个本地通知。我只需要定义注册后的下一个上午7点是1:00还是18:00。接下来的早上7点可能会晚24小时甚至2小时。正如你所看到的,在我的示例中,我将注册日的时间设置为9:00。然后我再加上24小时,所以总是第二天早上9点。哦,谢谢。它对我有用。现在,我如何使它作为一个循环工作一个月?我的意思是,每天发送三次不同的字符串。只需安排几个带有不同文本的通知。通过设置“repeatInterval”属性,可以使通知重复出现。