ios - 如何使用 swift 3 在消息应用程序中共享网址和文本

标签 ios swift3 message imessage

我必须将文本和 URL 分享到消息应用程序。

if (MFMessageComposeViewController.canSendText()) {
        let controller = MFMessageComposeViewController()

        //controller.subject =  "http://www.appzoy.com"

        //controller.attachments?.append(["url" : URL(string : "http://www.appzoy.com")!])

        //controller.addAttachmentURL(URL(string : "http://www.appzoy.com")!, withAlternateFilename: "")

        controller.body = "Hey I just gave an Awesome Assessment on UAssess App you can also try it. I scored \(String(describing: myScore!)) , Try to beat my score"

        controller.messageComposeDelegate = self
        self.present(controller, animated: true, completion: nil)
    }

    else  {

        Helper.sharedInstance.Print("No Message Composer Present" as AnyObject)
    }. 

我也尝试传递网址,但它不会向应用程序发送消息 任何人都知道如何在消息应用程序中共享 URL 链接和文本。

最佳答案

尝试下面的代码:

   let controller = MFMessageComposeViewController()

    if (MFMessageComposeViewController.canSendText()) {

        let urlToShare = "http://www.appzoy.com"

        controller.body = "Hey I just gave an Awesome Assessment on UAssess App you can also try it. I scored , Try to beat my score \(urlToShare)"

        controller.messageComposeDelegate = self
        self.present(controller, animated: true, completion: nil)
    }

enter image description here 希望这对您有帮助:)

关于ios - 如何使用 swift 3 在消息应用程序中共享网址和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46314087/

相关文章:

c++ - 从服务器发送推送通知

ios - 上传文件后是否可以运行代码,NSURLSession 配置为 backgroundSessionConfiguration

ios - 如何浏览文本字段(下一步/完成按钮)

wcf - 信任链错误 NetTcpBinding 与消息(用户名)安全性

java - 如何通过其他浏览器将文本写入Gmail邮件正文

iphone - IOS CATransform3DMakeRotation 需要矢量方面的帮助

arrays - 如何通过特定字符分隔 Swift 3 中的字符串

swift - UITableViewCell 创建

audio - 我想将输入节点的采样率从 44100 更改为 8000

windows - 向由不同窗口的用户 session 启动的应用程序发送消息