Adding text field in Remote Notification, iOS 8

后端 未结 3 1472
忘了有多久
忘了有多久 2020-12-07 17:14

i want to add facility in my iOS application that user can reply to the my message directly from the push notification. Like iMessage app is doing it in iOS 8. I am able to

3条回答
  •  清歌不尽
    2020-12-07 17:20

    You cannot do this in iOS 8 or below but the same is possible with iOS 9, I have written a blog post regarding the same. It is pretty simple,

     //creating the inline reply notification action
       let replyAction = UIMutableUserNotificationAction()
       replyAction.title = "Say Something"
       replyAction.identifier = "inline-reply"
       replyAction.activationMode = .Background
       replyAction.authenticationRequired = false
       replyAction.behavior = .TextInput
    
     //creating a category
       let notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
       notificationCategory.identifier = "INVITE_CATEGORY"
       notificationCategory .setActions([replyAction], forContext: UIUserNotificationActionContext.Default)
    
     //registerting for the notification.
          application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes:[ UIUserNotificationType.Sound, UIUserNotificationType.Alert,
                UIUserNotificationType.Badge], categories: NSSet(array:[notificationCategory]) as? Set))
    

    I was able to get it like below,

提交回复
热议问题