MFMessageComposeViewController - 禁用 adding/editing 收件人?

MFMessageComposeViewController - disable adding/editing of the recipients?

我知道这是一个老问题,我在文档中读到我们无法自定义 MFMessageController/MFMailController 的 UI 并且这样做会增加应用程序被标记的机会AppStore 如果他们发现我使用私人 APIS。所以现在我所做的只是为了探索私人 api 的

但我仍然遵循了一些文档,并尝试使用一些私有 API 的

来执行以下代码
@IBAction func sendSmsClick(_ sender: AnyObject) {
    guard MFMessageComposeViewController.canSendText() else {
        return
    }
    
    let messageController = MFMessageComposeViewController()
    messageController body = "fhfhfkjhfdgggefgregfhrfhfrhggejhvghjkgevhjg"
    messageController.recipients = ["64688098"]
    messageController.messageComposeDelegate = self;
    
    
    // Disabling the recepient editing - not working
    // Here the _setCanEditRecipients: is a private API
    let disableRecepients = "_setCanEditRecipients:"
    print(disableRecepients)
    let selOne = NSSelectorFromString(disableRecepients)
    if messageController.responds(to: selOne) {
        print("Yes")
       messageController.perform(selOne, with: false)
    }
    
    self.present(messageController, animated: true) {
       
    }
    
    
    
}

我从这里的 MFMessageComposeViewController 的 iVars 和方法列表中得到的私有 APIs。

https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MessageUI.framework/MFMessageComposeViewController.h

但我仍然能够编辑收件人列表,即使传递给私有 API 中的实例方法之一 _setCanEditRecipients 也是如此。如何禁用 MFMessageComposer 控制器中的添加按钮和收件人编辑?任何想法将不胜感激

尝试 1

MFMessageComposeViewController._setCanEditRecipients() - 在向用户显示屏幕之前(与您尝试的相同)- 没有用。


尝试 2

MFMessageComposeViewController 是一个 UINavigationController 子类,加载后您可以访问它的 viewControllers.

self.present(messageController, animated: true, completion: {
    let firstVC = messageController.viewControllers.first
    // This is a private class called `CKSMSComposeController` 
})

CKSMSComposeController.setCanEditRecipients() - 向用户呈现屏幕后(在呈现的完成处理程序中) - 不起作用。


尝试 3

尝试在所有其他视图上添加一个视图 - 覆盖收件人区域并且不允许交互?

self.present(messageController, animated: true, completion: {
    // Hard-coded frame value, needs to be tested thoroughly
    let view = UIView(frame: CGRect(x: 0, y: 70, width: messageController.view.bounds.width, height: 70))
    // Make alpha 0 after testing (added for showing what it covers)
    view.backgroundColor = UIColor.yellow.withAlphaComponent(0.3)
    view.autoresizingMask = [.flexibleWidth]
    view.isUserInteractionEnabled = false
    messageController.view.addSubview(view)
})

It is working as of Xcode 12.5 & iOS 14.6. As always with these hacks, the fix is not reliable and can break in any iOS release.