tldr:媒体部分是可解的,chromecast部分可能是不可能的。
应用扩展
Action Extension 允许您在当前页面上执行 JavaScript。然后,您可以在网页中搜索媒体链接,并允许用户选择他们希望观看的视频(例如,如果有多个视频)。这对于非常动态的页面可能是有问题的,但可能会起作用。我这样做是为了寻找带有id 的 HTML 元素,以使它们成为可链接/可书签的元素。
详情
我的应用扩展配置如下所示,但您可能希望使用 NSExtensionActivationSupportsMovieWithMaxCount,而不是 NSExtensionActivationRule 或 *SupportsWebPage* 或 *SupportsWebUrl*:
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebUrlWithMaxCount</key>
<integer>0</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>you_must_write_this.js</string>
</dict>
iOS 上的 Chrome 和 Firefox 没有显示我的应用扩展程序,但这可能是因为我的 NSActivationExtensionRule 不匹配。
NSExtensionJavaScriptPreprocessingFile 值是您包含在项目中的一个文件,它是用 JavaScript 编写的,符合here 描述的 API。您可能希望将其从 you_must_write_this.js 重命名。
ChromeCast
这部分我不确定,我现在正在查看,但是:Some APIs Are Unavailable to App Extensions 概述了应用扩展的限制。
[...] 应用扩展程序不能:
[...]
访问 sharedApplication 对象,因此不能使用该对象上的任何方法
在我正在编写的新 ChromeCast 应用程序中执行 grep -r sharedApplication ./Pods 显示:
Binary file ./Pods/google-cast-sdk/GoogleCastSDK-Public-3.2.0-Release/GoogleCast.framework/GoogleCast matches
请注意,还有一个限制是防止长时间运行代码,因此您编写的任何代码都必须在 App Extension UI 关闭时完成。 ChromeCast 当然可以继续,但是您的 UI 元素将被关闭(这会使重新连接到 ChromeCast 的速度变慢)。
我会尝试并回来,但我不是很有希望。
edit1:我目前的实验表明:
CastQuick log -[GCKNNetworkReachability startMonitoring] startMonitoring
CastQuick log -[GCKRuntimeConfiguration httpRequest:didFailWithError:] download request failed with: Error Domain=NSURLErrorDomain Code=-995 "(null)"
这似乎是一个应用扩展限制,要求 GoogleCast SDK 在使用 NSURLSession 时使用您包含应用的组 ID,因为后台上传和下载将与/打开主应用共享。
其他 API 必须公开一个可配置变量才能这样做,我的猜测是需要创建针对 GoogleCast API 的错误/增强功能。