【发布时间】:2015-10-31 13:23:02
【问题描述】:
我正在尝试使用本地通知,这是我的代码:
应用代理
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Sound, UIUserNotificationType.Alert, UIUserNotificationType.Badge], categories: nil))
notificationViewController
let localNotification:UILocalNotification = UILocalNotification()
var BDate = friend.birthday.componentsSeparatedByString("/")
let date = NSDate.date(year: 2015, month: Int(BDate[1])!, day: Int(BDate[0])! - daysBefore, hour: hour, minute: min, second: 0)
localNotification.soundName = "notificationSound.mp3"
localNotification.alertBody = friend.fullName + " has a birthday today!"
localNotification.fireDate = date
localNotification.timeZone = NSTimeZone.localTimeZone()
localNotification.repeatInterval = NSCalendarUnit.Year
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
friend.birthday 是一个字符串 - “DD/MM/YYYY”
我正在为朋友数组中的每个朋友调用 setNotification 函数。当只有一两个朋友时,我会收到通知,但有约 100 多个朋友时,我不再收到通知。
我知道 fireDate 是正确的,我检查过了。
为什么代码不起作用?
【问题讨论】:
-
修复了,还是不行
-
你检查过你设置的开火日期吗?
-
是的,日期正确
-
@OmerN 你需要在设置fireDate之前设置timeZone
标签: ios swift notifications uilocalnotification