【发布时间】:2015-09-02 07:14:59
【问题描述】:
我创建了苹果手表应用程序来显示推送通知。所以我创建了不同类别的不同动态通知界面。但它没有显示动态界面但能够看到相应类别的操作按钮。请帮助我。请找到appdelegate 推送通知注册方法
P.S:如果在带有有效负载的模拟器中运行,它工作正常。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// Register for Push Notitications, if running iOS 8
if application.respondsToSelector("registerUserNotificationSettings:") {
self.registerSettingsAndCategories()
} else {
// Register for Push Notifications before iOS 8
application.registerForRemoteNotifications()
}
return true
}
func registerSettingsAndCategories() {
let alarmAction = UIMutableUserNotificationAction()
alarmAction.title = NSLocalizedString("Activate Theft Alarm ", comment: "Activate Theft Alarm ")
alarmAction.identifier = "theftAlarm"
alarmAction.activationMode = UIUserNotificationActivationMode.Foreground
alarmAction.authenticationRequired = false
let callCopsAction = UIMutableUserNotificationAction()
callCopsAction.title = NSLocalizedString("Call Near by cops", comment: "Call Near by cops")
callCopsAction.identifier = "callCops"
callCopsAction.activationMode = UIUserNotificationActivationMode.Foreground
callCopsAction.authenticationRequired = false
let callSecAction = UIMutableUserNotificationAction()
callSecAction.title = NSLocalizedString("Call Parking Security ", comment: "Call Parking Security ")
callSecAction.identifier = "callSecurity"
callSecAction.activationMode = UIUserNotificationActivationMode.Foreground
callSecAction.authenticationRequired = false
let navigateToSpotAction = UIMutableUserNotificationAction()
navigateToSpotAction.title = NSLocalizedString("Navigate to Spot", comment: "Navigate to Spot")
navigateToSpotAction.identifier = "navigateToSpot"
navigateToSpotAction.activationMode = UIUserNotificationActivationMode.Foreground
navigateToSpotAction.authenticationRequired = false
let bookappointmentAction = UIMutableUserNotificationAction()
bookappointmentAction.title = NSLocalizedString("Book Appointment", comment: "Book Appointment")
bookappointmentAction.identifier = "bookAppointment"
bookappointmentAction.activationMode = UIUserNotificationActivationMode.Foreground
bookappointmentAction.authenticationRequired = false
let theftCategory = UIMutableUserNotificationCategory()
theftCategory.setActions([alarmAction, callCopsAction,callSecAction],
forContext: UIUserNotificationActionContext.Default)
theftCategory.setActions([callCopsAction,callSecAction], forContext: UIUserNotificationActionContext.Minimal)
theftCategory.identifier = "theftWarning"
let accidentCategory = UIMutableUserNotificationCategory()
accidentCategory.setActions([navigateToSpotAction], forContext: UIUserNotificationActionContext.Default)
accidentCategory.setActions([navigateToSpotAction], forContext: UIUserNotificationActionContext.Minimal)
accidentCategory.identifier = "accident"
let lowOilCategory = UIMutableUserNotificationCategory()
lowOilCategory.setActions([bookappointmentAction], forContext: UIUserNotificationActionContext.Default)
lowOilCategory.setActions([bookappointmentAction], forContext: UIUserNotificationActionContext.Minimal)
lowOilCategory.identifier = "lowOil"
let categories : Set<UIUserNotificationCategory> = [theftCategory, accidentCategory, lowOilCategory]
// Configure other actions and categories and add them to the set...
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
UIApplication.sharedApplication().registerForRemoteNotifications()
}
【问题讨论】:
标签: apple-push-notifications watchkit apple-watch