gpt4 book ai didi

iOS 14.5 或 14.6 及以上版本访问共享扩展中的 UIApplication.shared.open 或 UIApplication.shared.openURL 会给出 "APPLICATION_EXTENSION_API_ONLY"

转载 作者:行者123 更新时间:2023-12-03 08:20:54 27 4
gpt4 key购买 nike

在 iOS 14.5 或 14.6 之前,我们可以通过将 仅需要 App-Extension-Safe API 设置为 NO 并使用:

if #available(iOS 10.0, *) {
UIApplication.shared.open(urlToOpen, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(urlToOpen)
}

但是从 iOS 14.5 或 14.6 开始,我们在构建时会遇到此错误:

Application extensions and any libraries they link to must be built with the `APPLICATION_EXTENSION_API_ONLY` build setting set to YES.

有没有办法从 iOS 14.5/14.6 中的共享表扩展启动主应用程序?

最佳答案

我想出了一个解决方案,可以让您启动主应用程序,同时将仅需要应用程序扩展安全API设置为YES

按照 Apple 的要求,将仅需要应用程序扩展安全 API 设置为 YES

然后在扩展中使用它:

let sharedSelector = NSSelectorFromString("sharedApplication")
let openSelector = NSSelectorFromString("openURL:")

if let urlToOpen = URL(string: "YOURAPPURLSCHEME://whatever_you_need_to_pass"), UIApplication.responds(to: sharedSelector), let shared = UIApplication.perform(sharedSelector)?.takeRetainedValue() as? UIApplication, shared.responds(to: openSelector) {

shared.perform(openSelector, with: urlToOpen)

}

//do the rest of extension completion stuff....
self.extensionContext?.completeRequest(returningItems: [], completionHandler:nil)

关于iOS 14.5 或 14.6 及以上版本访问共享扩展中的 UIApplication.shared.open 或 UIApplication.shared.openURL 会给出 "APPLICATION_EXTENSION_API_ONLY",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67864793/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com