OStack程序员社区-中国程序员成长平台

标题: ios - 如何使用 swift 3 在消息应用程序中共享 URL 和文本 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 02:37
标题: ios - 如何使用 swift 3 在消息应用程序中共享 URL 和文本

我必须将文本和 URL 分享到 Message App。

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,但它不会向 App 发送消息 任何人都知道如何在消息应用程序中共享 URL 链接和文本。



Best Answer-推荐答案


试试下面的代码:

   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 在消息应用程序中共享 URL 和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46314087/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4