Ask for User Permission to Receive UILocalNotifications in iOS 8

前端 未结 5 690
自闭症患者
自闭症患者 2020-11-29 15:54

I have set up local notifications in the App Delegate Using this:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UILocalNotificati         


        
5条回答
  •  悲&欢浪女
    2020-11-29 16:18

    **Local Notification with three button action for iOS8+

    //Button : I TOOK IT , REMIND LATER , SKIP IT**

            let completeAction = UIMutableUserNotificationAction()
            completeAction.identifier = "COMPLETE_TODO"
            completeAction.title = "I TOOK IT"
            completeAction.activationMode = .Background
            completeAction.destructive = true
            completeAction.authenticationRequired = false
    
            let remindAction = UIMutableUserNotificationAction()
            remindAction.identifier = "REMIND_TODO"
            remindAction.title = "REMIND LATER"
            remindAction.activationMode = .Background
            remindAction.destructive = false
            //  remindAction.authenticationRequired = false
    
            let skipAction = UIMutableUserNotificationAction()
            skipAction.identifier = "SKIP_TODO"
            skipAction.title = "SKIP IT"
            skipAction.activationMode = .Background
            skipAction.destructive = false
            skipAction.authenticationRequired = false
    
    
            let todoCategory = UIMutableUserNotificationCategory()
            todoCategory.identifier = "TODO_CATEGORY"
            todoCategory.setActions([completeAction, remindAction, skipAction], forContext: .Default)
            todoCategory.setActions([completeAction,remindAction,skipAction], forContext: .Minimal)
    
    
            if application.respondsToSelector("isRegisteredForRemoteNotifications")
            {
    
                let categories = NSSet(array: [todoCategory,todoVideoCategory])
                let types:UIUserNotificationType = ([.Alert, .Sound, .Badge])
    
                let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: categories as? Set)
    
                application.registerUserNotificationSettings(settings)
                application.registerForRemoteNotifications()
    
            }
    
        }
    

提交回复
热议问题