【问题标题】:Swift 3 : How to add a link in imessage?Swift 3:如何在 imessage 中添加链接?
【发布时间】:2017-08-27 05:12:07
【问题描述】:

我正在尝试在 iMessage Sticker 应用中添加链接。该链接将打开 iTunes 贴纸商店页面。当我在 MessagesViewController.swift 文件中添加这些代码时,我得到一个错误“'shared' is unvailable: Use view controller based solutions where applicable”。如何正确添加链接?

 func clickMe(sender:UIButton!)
{
    UIApplication.shared.open(URL(string: "itms-apps://itunes.apple.com/app/id11111111")!)
    print("Button Clicked")
}

【问题讨论】:

  • MessagesViewController 是 UIViewViewContoller 的子类吗?

标签: ios swift sdk imessage imessage-extension


【解决方案1】:

转到您的 Xcode 构建设置,然后搜索扩展并将“仅需要 App-extension-safe Api”的值从“是”更改为“否”,然后您可以访问而不会出现任何错误。

UIApplication.shared.open(URL(string: "your url address")!)

【讨论】:

    【解决方案2】:

    iOS 扩展有一些限制,因此您无法访问您可以从应用访问的所有 API。

    某些 API 不适用于应用扩展

    由于其在系统中的主要作用,应用扩展程序没有资格参与某些活动。应用扩展不能:

    访问一个 sharedApplication 对象,因此不能使用该对象上的任何方法...

    更多详情请查看App Extension Programming Guide

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 2017-01-14
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 2017-01-17
      相关资源
      最近更新 更多