[英]Writing an iOS 8 share extension without a storyboard
Does anyone know of a good way to write an iOS 8 share extension without the MainInterface.storyboard
that comes with the template? 有没有人知道在没有模板附带的MainInterface.storyboard
情况下编写iOS 8共享扩展的好方法?
When I delete the file or remove the NSExtensionMainStoryboard
from Info.plist
, the extension stops working (nothing happens when you tap on the button in the share pane). 当我删除文件或从Info.plist
删除NSExtensionMainStoryboard
时,扩展程序停止工作(当您点击共享窗格中的按钮时没有任何反应)。 We tried replacing NSExtensionMainStoryboard
with NSExtensionPrincipalClass
which also didn't work. 我们试图更换NSExtensionMainStoryboard
与NSExtensionPrincipalClass
也没有工作。
Any ideas? 有任何想法吗?
Figured it out! 弄清楚了!
Turns out there's a weird module naming thing going on in Swift, so you can fix it by adding an @objc
name to the class: 事实证明,在Swift中有一个奇怪的模块命名事件,所以你可以通过在类中添加一个@objc
名称来修复它:
@objc(PrincipalClassName)
class PrincipalClassName: UIViewController {
...
and then set the NSExtensionPrincipalClass
key to PrincipalClassName
. 然后将NSExtensionPrincipalClass
键设置为PrincipalClassName
。
Found the answers from these answers combined Answer 1 and Answer 2 . 从这些答案中找到答案,并结合答案1和答案2 。
For Objective-C you will have to put the following in the info.plist
of the App extension: NSExtensionPrincipalClass
and make sure that it is under NSExtension
Dict 对于Objective-C,您必须将以下内容放在App扩展的info.plist
中: NSExtensionPrincipalClass
并确保它在NSExtension
Dict下
So full answer should be like this , in my case ActionViewController
is the App extension viewController 所以完整答案应该是这样的,在我的情况下, ActionViewController
是App扩展视图控制器
无法添加注释但它不再是NSPrincipalClass而是NSExtensionPrincipalClass
Instead of the @objc
hack, the proper way to do it in Swift is to include the module name in NSExtensionPrincipalClass
, ie, 而不是@objc
hack,在Swift中执行它的正确方法是在NSExtensionPrincipalClass
包含模块名称,即,
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).ActionViewController</string>
(Documenting the error otherwise: (否则记录错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: ...)'
Hopefully will help someone who run into this error in the future.) 希望将来可以帮助遇到此错误的人。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.