Swift2 推送时发出声音通知

Swift2 推送时发出声音通知,swift2,Swift2,海洛之友 我创建了一个代码来推动nofication,但是通知是愚蠢的,我需要使用声音, 在这一行中,我指定了以下类型: let notificationTypes = UIUserNotificationType.Alert 但是不要工作。 另一个问题,我如何使用徽章在应用程序图标中添加数字 这是我的代码: func setupNotificationSettings() { let notificationSettings: UIUserNotificationSetting

海洛之友

我创建了一个代码来推动nofication,但是通知是愚蠢的,我需要使用声音, 在这一行中,我指定了以下类型:

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)  
func setupNotificationSettings(){
让notificationSettings:UIUserNotificationSettings!=UIApplication.sharedApplication().currentUserNotificationSettings()
如果(notificationSettings.types==UIUserNotificationType.None){
让notificationTypes=UIUserNotificationType.Alert
让modifyListAction=UIMutableUserNotificationAction()
modifyListAction.identifier=“editList”
modifyListAction.title=“编辑列表”
modifyListAction.activationMode=UIUserNotificationActivationMode.前台
modifyListAction.destructive=false
modifyListAction.authenticationRequired=true
让TrasAction=UIMutableUserNotificationAction()
trashAction.identifier=“trashAction”
trashAction.title=“删除列表”
TrashaAction.activationMode=UIUserNotificationActivationMode.Background
trashAction.destromical=true
trashAction.authenticationRequired=true
let actionsArray=NSArray(对象:modifyListAction、TrasAction)
let actionsArrayMinimal=NSArray(对象:trashAction,modifyListAction)
/  
let ShoppingListMemberCategory=UIMutableUserNotificationCategory()
shoppingListReminderCategory.identifier=“shoppingListReminderCategory”
shoppingListReminderCategory.setActions(actionsArray为?[UIUserNotificationAction],forContext:UIUserNotificationActionContext.Default)
shoppingListReminderCategory.setActions(actionsArrayMinimal为?[UIUserNotificationAction],forContext:UIUserNotificationActionContext.Minimal)
let categoriesForSettings=NSSet(对象:shoppingListReminderCategory)
/  
让newNotificationSettings=UIUserNotificationSettings(forTypes:notificationTypes,categories:categories for设置为?Set)
UIApplication.sharedApplication().registerUserNotificationSettings(newNotificationSettings)
}  
}  
func pushNotificationTest(){
让localNotification=UILocalNotification()
localNotification.fireDate=fixNotificationDate(datePicker.date)//usar com datePicker
localNotification.alertBody=“测试”
localNotification.alertAction=“测试”
localNotification.category=“ShoppingListMemberCategory”
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)

}您没有请求足够的权限。您只请求了
.Alert
,但是
.Sound
.Badge
都应该包括在内。更改:

let notificationTypes = UIUserNotificationType.Alert
致:

要添加徽章编号,请使用:

localNotification.applicationIconBadgeNumber = 1
localNotification.applicationIconBadgeNumber = 1