我相信我正在正确地创建交互式通知,但是我在跳板/锁定屏幕上没有按钮的情况下收到通知.我究竟做错了什么?
AppDelegate中:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { let notificationSettings: UIUserNotificationSettings! = UIApplication.sharedApplication().currentUserNotificationSettings() /// don't want to constantly set/re-set when this function fires if (notificationSettings.types == UIUserNotificationType.None){ let yesAction = UIMutableUserNotificationAction() yesAction.identifier = "yesAction" yesAction.title = "Yes" yesAction.destructive = false yesAction.authenticationRequired = false yesAction.activationMode = UIUserNotificationActivationMode.Background let noAction = UIMutableUserNotificationAction() noAction.identifier = "noAction" noAction.title = "No" noAction.destructive = false noAction.authenticationRequired = false noAction.activationMode = UIUserNotificationActivationMode.Background let stopAction = UIMutableUserNotificationAction() stopAction.identifier = "stopAction" stopAction.title = "Stop" stopAction.destructive = true stopAction.authenticationRequired = false stopAction.activationMode = UIUserNotificationActivationMode.Background let encouragementCategory = UIMutableUserNotificationCategory() encouragementCategory.identifier = "GOCEncouragement" encouragementCategory.setActions([yesAction, noAction, stopAction], forContext: UIUserNotificationActionContext.Default) encouragementCategory.setActions([yesAction, noAction], forContext: UIUserNotificationActionContext.Minimal) let settings = UIUserNotificationSettings(forTypes: [.Alert, .Sound], categories: Set.init(arrayLiteral: encouragementCategory)) UIApplication.sharedApplication().registerUserNotificationSettings(settings) } return true }
其他地方,叫做application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings)
:
notificationArray.forEach({ let notification = UILocalNotification.init() notification.fireDate = fireDay notification.soundName = UILocalNotificationDefaultSoundName notification.alertBody = $0["Encouragement"] as! String! notification.repeatInterval = .Month notification.category = "GOCEncouragement" notification.userInfo = [ "UUID" : $0["UUID"] as! Int] if #available(iOS 8.2, *) { notification.alertTitle = "Choices Encouragement" } UIApplication.sharedApplication().scheduleLocalNotification(notification) nextDay.day++ fireDay = NSCalendar.currentCalendar().dateByAddingComponents(nextDay, toDate: fireDay!, options: NSCalendarOptions.init(rawValue: 0)) })
重新解决问题; 通知按计划显示,但锁定屏幕上的左侧滑动不会显示任何按钮,也不会拖拽主屏幕.
欢迎任何建议!
编辑:认为它只是模拟器,但也在现场9.2设备上.其他iOS版本按预期工作.