1
直升機朋友聲音推送通知
我創建了一個碼推nofication,但通知的silient,我需要使用聲音, 在此行中我指定的類型:
let notificationTypes = UIUserNotificationType.Alert
但不工作。 另一個問題,我如何使用徽章在應用程序圖標中添加數字?
這是我的代碼:
func setupNotificationSettings() {
let notificationSettings: UIUserNotificationSettings! = UIApplication.sharedApplication().currentUserNotificationSettings()
if (notificationSettings.types == UIUserNotificationType.None){
let notificationTypes = UIUserNotificationType.Alert
let modifyListAction = UIMutableUserNotificationAction()
modifyListAction.identifier = "editList"
modifyListAction.title = "Edit list"
modifyListAction.activationMode = UIUserNotificationActivationMode.Foreground
modifyListAction.destructive = false
modifyListAction.authenticationRequired = true
let trashAction = UIMutableUserNotificationAction()
trashAction.identifier = "trashAction"
trashAction.title = "Delete list"
trashAction.activationMode = UIUserNotificationActivationMode.Background
trashAction.destructive = true
trashAction.authenticationRequired = true
let actionsArray = NSArray(objects: modifyListAction, trashAction)
let actionsArrayMinimal = NSArray(objects: trashAction, modifyListAction)
/
let shoppingListReminderCategory = UIMutableUserNotificationCategory()
shoppingListReminderCategory.identifier = "shoppingListReminderCategory"
shoppingListReminderCategory.setActions(actionsArray as? [UIUserNotificationAction], forContext: UIUserNotificationActionContext.Default)
shoppingListReminderCategory.setActions(actionsArrayMinimal as? [UIUserNotificationAction], forContext: UIUserNotificationActionContext.Minimal)
let categoriesForSettings = NSSet(objects: shoppingListReminderCategory)
/
let newNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categoriesForSettings as? Set<UIUserNotificationCategory>)
UIApplication.sharedApplication().registerUserNotificationSettings(newNotificationSettings)
}
}
func pushNotificationTest(){
let localNotification = UILocalNotification()
localNotification .fireDate = fixNotificationDate(datePicker.date) //usar com datepicker
localNotification.alertBody = "Test"
localNotification.alertAction = "Test test test"
localNotification.category = "shoppingListReminderCategory"
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
非常好。感謝您的幫助,解決問題 –