在高级通知会议 708 WWDC 2016结束时。他们谈到了同时进行文本输入和操作。
从 WWDC 会话 708 的 24 分钟开始。
您对派对邀请发表评论并同时接受或拒绝邀请。我试图这样做,但非常不成功。
class NotificationViewController: UIViewController, UNNotificationContentExtension {
var textField = UITextField(frame: CGRect(x: 0, y: 0, width: 100, height: 10))
override func viewDidLoad() {
super.viewDidLoad()
// Do any required interface initialization here.
}
override var canBecomeFirstResponder: Bool {
return true
}
override var inputAccessoryView: UIView? {
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 40))
customView.backgroundColor = UIColor.red
textField.placeholder = "Type Comment here"
textField.textColor = UIColor.black
customView.addSubview(textField)
print(customView)
return customView
}
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
if response.actionIdentifier == "comment" {
becomeFirstResponder()
textField.becomeFirstResponder()
print("Its working")
if let textResponse = response as? UNTextInputNotificationResponse {
print(textResponse.userText)
completion(UNNotificationContentExtensionResponseOption.doNotDismiss)
}
completion(UNNotificationContentExtensionResponseOption.doNotDismiss)
}
}
}