创建没有UI的iOS操作扩展 [英] Create iOS Action Extension with no UI
问题描述
我正在尝试创建类似于iOS中可用的系统复制"操作的操作扩展.
我找到了不同的答案,说不可能有非全屏UI,但是根据 Apple官方文档,可能没有UI(我想就像在复制"操作中一样).
I am trying to create an Action Extension similar to the system "Copy" action available in iOS.
I found different answers saying it's not possible to have non-fullscreen UI, but according to Apple Official Documentation it is possible to have no UI (like in the Copy action, I presume).
操作(iOS和macOS; UI和非UI变体)
Action (iOS and macOS; UI and non-UI variants)
我尝试创建透明视图,但结果始终是全屏黑色覆盖.
我已经在我的 Info.plist
中将 NSExtensionActionWantsFullScreenPresentation
指定为 NO
,但是没有任何变化.
I have tried creating a transparent view, but the result is always a fullscreen black overlay.
I have already specified NSExtensionActionWantsFullScreenPresentation
to NO
in my Info.plist
, but nothing changes.
关于如何做到这一点的任何想法?
Any idea about how to do it?
推荐答案
要回答我自己的问题:实际上可以通过分配属性 NSExtensionRequestHandling 协议.
To answer my own question: it is actually possible to create a non-UI Action Extension on iOS by assigning the property NSExtensionPrincipalClass to a class implementing a NSExtensionRequestHandling protocol.
示例:
class ActionRequestHandler: NSObject, NSExtensionRequestHandling {
var extensionContext: NSExtensionContext?
func beginRequest(with context: NSExtensionContext) {
// Do not call super in an Action extension with no user interface
self.extensionContext = context
// Do stuff with the context
}
}
创建扩展的最简单方法是添加一个新目标(文件">新建">目标"),选择操作扩展",然后在操作类型.
The easiest way to create an extension like this is to add a new target (File > New > Target), select Action Extension and then select No User Interface in the Action Type.
这篇关于创建没有UI的iOS操作扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!