2016-07-15 4 views
1

Helo друзейЗвук на уведомления Push-

Я создал код, чтобы подтолкнуть 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) 

}

ответ

2

Вы не запрашивали достаточно прав. Вы запросили только .Alert, но .Sound и .Badge все должны быть включены. Изменение:

let notificationTypes = UIUserNotificationType.Alert 

к:

let notificationTypes: UIUserNotificationType = [.Alert, .Sound, .Badge] 

Чтобы добавить номер жетона, используйте:

localNotification.applicationIconBadgeNumber = 1 
+0

Очень хорошее. Спасибо за помощь, исправьте проблему –

Смежные вопросы