I recently updated to Xcode 7 beta and I am having an issue with scheduling UILocalNotifications. If anyone can figure out why they are not functional, I would really appreciate some help. Don't worry about those other classes like Time and Date, those are pretty self explanatory and I have verified that they work fine.
我最近更新到Xcode 7 beta,我遇到了调度UILocalNotifications的问题。如果有人能弄清楚他们为什么不起作用,我真的很感激一些帮助。不要担心像时间和日期这样的其他类,那些是非常自我解释的,我已经证实它们工作正常。
My object:
我的目标:
class NotificationWithTime {
var UINotification = UILocalNotification()
init(title: String, day: Date, time: Time) {
let formatter = NSDateFormatter()
let dayday = day.day
let dayMonth = day.month
let dayYear = day.year
let timeMinute = time.minute
var timeHour = time.hour
if time.tod == TOD.PM {
timeHour! += 12
}
formatter.dateFormat = "yyyy-MM-dd HH:mm"
formatter.timeZone = NSTimeZone(abbreviation: "EST")
UINotification.alertAction = title
UINotification.fireDate = formatter.dateFromString("\(dayYear)-\(dayMonth)-\(dayday) \(timeHour!):\(timeMinute!)")
UIApplication.sharedApplication().scheduleLocalNotification(UINotification)
//print("set a new notification for" + "\(dayMonth)-\(dayday)-\(dayYear) \(timeHour):\(timeMinute)")
}
}
My instance:
我的实例:
let time = ScheduleGenerator.refineTime(Time(t: TOD.PM, d: 20, h: 8, m: 12, s: 0))
_ = NotificationWithTime(title: "chicke is good", day: ScheduleGenerator.refineDate(Date(m: 9, d: 19, y: 2015)), time: time)
1 个解决方案
#1
3
In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver.
在iOS 8及更高版本中,使用本地或远程通知的应用程序必须注册他们打算提供的通知类型。
Swift
迅速
let mySettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil);
UIApplication.sharedApplication().registerUserNotificationSettings( mySettings);
Objective-C
Objective-C的
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
#1
3
In iOS 8 and later, apps that use either local or remote notifications must register the types of notifications they intend to deliver.
在iOS 8及更高版本中,使用本地或远程通知的应用程序必须注册他们打算提供的通知类型。
Swift
迅速
let mySettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil);
UIApplication.sharedApplication().registerUserNotificationSettings( mySettings);
Objective-C
Objective-C的
UIUserNotificationType types = UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];