ios - sharedApplication() 在 Today Extension 中无法快速工作

标签 ios swift

我是 swift 的新手,我创建了一个今日小部件,并向其添加了一个按钮。在该按钮的操作中,我想在 safari 中启动一个 url,但“sharedApplication()”不起作用,我在普通 View Controller 中使用此代码:

override func viewDidLoad() {
        super.viewDidLoad()
        UIApplication.sharedApplication().openURL(NSURL(string: "facetime:mahdi@gmail.com")!)
        // Do any additional setup after loading the view, typically from a nib.
    }

但它在 Today App Extension 中不起作用。

最佳答案

您不能在应用扩展中使用 sharedApplication

如今,小部件可以使用 NSExtensionContext 上的 openUrl:completionHandler: 方法打开 url,因此您可以:

extensionContext?.openURL(NSURL(string: "facetime:mahdi@gmail.com")!, completionHandler: nil)

不过,您应该在按钮的点击处理程序中执行此操作,而不是在 viewDidLoad 中执行此操作。

但请注意,苹果文档指出:

IMPORTANT

Apple allows any Today widget to use the openURL:completionHandler: method to open the widget’s own containing app.

If you employ this method to open other apps from your Today widget, your App Store submission might entail additional review to ensure compliance with the intent of Today widgets.

To learn more, read App Store Review Guidelines and iOS Human Interface Guidelines, linked to from Apple’s App Review Support page

关于ios - sharedApplication() 在 Today Extension 中无法快速工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31187584/

相关文章:

ios - 如何计算UIViewController内部内容的高度?

ios - 如何在 facebook ios 中获取访问 token

javascript - Firebase 使用 onCreate 部署获取 ID 以获取推送通知

ios - iOS Safari 和 Chrome 上的 Z-index 问题

ios - 为什么某些坐标(纬度和经度)不适用于 Google Maps SDK for iOS API?

ios - captureStillImageAsynchronouslyFromConnection 返回 nil 错误

ios - 如何在 Swift 项目中使用 Obj-c 库/自定义接口(interface)

ios - NSURLSessionTask 在 session 重新连接后是否保留 taskIdentifier?

ios - 将 CIFilter 应用于 UIImagePickerController 提要

ios - UIButton titleLabel 文本位于其框架底部