如何使用swift 3在Masseage应用中分享网址和文字

时间:2017-09-20 05:42:54

标签: ios swift3 message imessage

我必须与Message App共享文本和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)
    }. 

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

1 个答案:

答案 0 :(得分:2)

尝试以下代码:

   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 希望这会对你有所帮助:)。