在远程通知,iOS 8中添加文本字段

Iqb*_*han 26 iphone cocoa-touch objective-c push-notification ios8

我想在我的iOS应用程序中添加工具,用户可以直接从推送通知回复我的消息.就像iMessage应用程序在iOS 8中一样.我可以添加按钮来推送通知,但没有找到任何有关如何添加文本字段的指南.请帮忙.提前致谢.

-------------------------------------------------- ----------------------------------------

我知道如何添加操作(按钮),但如何添加文本字段或文本视图以进行输入

在此输入图像描述

Leo*_*ica 15

在询问时,使用提供的API无法做到这一点.UIUserNotificationAction对象仅表示您可以添加的其他按钮,但不能直接输入文本.现在,您应该添加一个"回复"按钮,然后点按,打开应用程序,键盘可见,以便用户可以回复.

使用iOS 9 SDK,可以通过设置UIUserNotificationActionBehaviorTextInputbehavior通知操作来实现.请务必阅读文档以获取更多信息.

有关如何在Swift中实现此目的的示例,请参阅答案.


Sat*_*ran 11

你无法在iOS 8或更低版本中执行此操作,但iOS 9也可以这样做,我写了一篇关于相同的博客文章.这很简单,

 //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<UIUserNotificationCategory>))
Run Code Online (Sandbox Code Playgroud)

我能够像下面那样得到它,

在此输入图像描述