我想从我的应用中打开imessage,并在文本字段中填入“分享我的应用...”(底部的消息字段,而不是电话号码字段)
我可以使用以下代码行打开我应用中的消息:
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
但我不知道如何传递消息。是否可以这样做而不是使用MFMessageComposeViewController()?我不能将此用于我遇到的后台播放问题,谢谢。
答案 0 :(得分:5)
与@Kuldeep的回应非常相似
let sms: String = "sms:+1234567890&body=Hello Abc How are You I am ios developer."
let strURL: String = sms.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
UIApplication.shared.open(URL.init(string: strURL)!, options: [:], completionHandler: nil)
似乎为我做了这个伎俩,非常感谢Kuldeep帮我这么做; )
答案 1 :(得分:2)
试试这个。
let sms: String = "sms:+1234567890&body=Hello Abc How are You I am ios developer."
UIApplication.shared.open(URL.init(string: sms.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!)!, options: [:], completionHandler: nil)
答案 2 :(得分:1)
尝试以下步骤在iMessage上发送文字
实施MFMessageComposeViewControllerDelegate
在按钮操作中添加以下代码
if MFMessageComposeViewController.canSendText() {
let controller = MFMessageComposeViewController()
controller.body = "Your Text here"
controller.messageComposeDelegate = self
controller.recipients = []
self.present(controller, animated: true, completion: nil)
}
实施MFMessageComposeViewControllerDelegate
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
controller.dismiss(animated: true, completion: nil)
}