iOS 11 imessage扩展message.url无法打开Safari [英] ios 11 imessage extension message.url does not open safari

查看:139
本文介绍了iOS 11 imessage扩展message.url无法打开Safari的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向应用程序添加iMessage extension目标.该扩展应该发送具有url属性的消息.我期望用户触摸消息时的行为是使用消息的url属性打开浏览器.

I'm adding an iMessage extension target to my app. The extension is supposed to send a message that has a url attribute. The behaviour I'm expecting when a user touches the message is to open the browser using the url attribute of the message.

我的messageView中有一个执行该代码的按钮:

I have a button in my messageView which executes this code:

@IBAction func labelButton(_ sender: Any) {
        let layout = MSMessageTemplateLayout()
        layout.imageTitle = "iMessage Extension"
        layout.caption = "Hello world!"
        layout.subcaption = "Test sub"
        guard let url: URL = URL(string: "https://google.com") else { return }

        let message = MSMessage()
        message.layout = layout
        message.summaryText = "Sent Hello World message"
        message.url = url

        activeConversation?.insert(message, completionHandler: nil)
    }

如果我触摸该消息,它将展开MessageViewController

If I touch the message, it expands the MessageViewController

然后我添加了这个:

override func didSelect(_ message: MSMessage, conversation: MSConversation) {

        if let message = conversation.selectedMessage {
            // message selected

            // Eg. open your app:
            self.extensionContext?.open(message.url!, completionHandler: nil)
        }
}

现在,当我触摸消息时,它会打开我的主应用程序,但仍然不会打开我的浏览器.

And now, when I touch the message, it opens my main app but still not my browser.

我在另一篇帖子上看到了(我无法对此发表评论,因此我打开了这篇文章)无法在Safari中打开,但是我有

I have seen on another post (where I cannot comment, thus I opened this post) that it is impossible to open in Safari but I have a news app which inserts links to articles and allows with a click on the message to open the article in a browser window, while the app is installed.

那么,有人可以告诉我如何继续在浏览器窗口中强制打开链接吗?

So, can someone please tell how I can proceed to force opening the link in a browser window?

非常感谢您.

推荐答案

以下是在消息中插入链接的技巧.不允许创建具有url属性的对象,而只能直接插入将在Safari中打开的链接.

Here is a trick to insert a link in a message. It does not allow to create an object that has an url attribute but just to insert a link directly which will open in Safari.

activeConversation?.insertText("https://google.com", completionHandler: nil)

这篇关于iOS 11 imessage扩展message.url无法打开Safari的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆