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

时间:2016-03-29 07:21:40

标签: ios swift

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

1 个答案:

答案 0 :(得分:0)

安排本地通知。

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)

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html