Hello StackOverflow friends,
I am integrating a MFMessageViewController and I want to disable the editing area of it either by disallowing the keyboard to appear or by disabling the user interaction to it. Currently my code is :
import UIKit
import MessageUI
class ViewController: UIViewController,MFMessageComposeViewControllerDelegate,UITextFieldDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func sendSmsClick(_ sender: AnyObject) {
guard MFMessageComposeViewController.canSendText() else {
return
}
let messageVC = MFMessageComposeViewController()
UIButton.appearance(whenContainedInInstancesOf: [MFMessageComposeViewController.self]).isUserInteractionEnabled = false
messageVC.body = "Enter a message hjhjhjkhjkhjhjhjjhgjhghjgjhghjghjghjghjgjhghjghjgjhghjghjghghjghjghjghghjghjhjghjghjghhvvvbnvhvhghghguyguygyugugigiugiouiopuopuoppuuo";
messageVC.recipients = ["Enter tel-nr"]
messageVC.messageComposeDelegate = self;
NSLog("Subviews %@", messageVC.view.subviews);
// self.view.endEditing(true)
self.present(messageVC, animated: false) {
// self.getAllSubviews(view: messageVC.view)
messageVC.view.loopViewHierarchy { (view, stop) in
if view is UIButton {
/// use the view
print("here")
stop = true
}
}
}
}
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
switch (result.rawValue) {
case MessageComposeResult.cancelled.rawValue:
print("Message was cancelled")
self.dismiss(animated: true, completion: nil)
case MessageComposeResult.failed.rawValue:
print("Message failed")
self.dismiss(animated: true, completion: nil)
case MessageComposeResult.sent.rawValue:
print("Message was sent")
self.dismiss(animated: true, completion: nil)
default:
break;
}
}
It is working fine and I just want to get to know the specific UIElement which is above the keyboard and I want to disable it for for further editing. How can I achieve this ?
You could try printing the view hierarchy and find your text field from the subviews, the problem is - all of this UI is running into a different environment than your app and you won't find anything useful there.
This
_UIRemoteViewwill get in your way and you won't be able to find your targettextField/buttonin the view hierarchy.What else can we do?
How to find what private apis can we use?
With above code, if you try to inspect
MFMessageComposeViewControllerclass, you will see following._setShouldDisableEntryFieldlooks interesting. How to use this?Does it work?
Why all the dance to get to the selector name?
Maybe (and that's a BIG MAYBE) it will help avoid a rejection like following.