iOS 8共享扩展loadItemForTypeIdentifier:options:completionHandler:完成关闭未执行 [英] iOS 8 Share extension loadItemForTypeIdentifier:options:completionHandler: completion closure not executing
问题描述
我在NSItemProvider对象上使用
loadItemForTypeIdentifier:options:completionHandler:方法,通过iOS 8中的Share扩展从Safari中提取网址。
I'm using the loadItemForTypeIdentifier:options:completionHandler: method on an NSItemProvider object to extract a url from Safari via a Share extension in iOS 8.
在Objective-C中,此代码和工作以及块运行。
In Objective-C, this code and works and the block runs.
[itemProvider loadItemForTypeIdentifier:(@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
//My code
}];
在Swift中,它看起来非常相似,但是闭包没有运行。另外, itemProvider.hasItemConformingToTypeIdentifier(public.url)
返回 YES
所以必须有一个有效的对象来解析 itemProvider
中的url。
In Swift, it looks very similar, however the closure doesn't run. Also, itemProvider.hasItemConformingToTypeIdentifier("public.url")
returns YES
so there must be a valid object to parse the url from inside the itemProvider
.
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in
//My code
})
Info.plist NSExtension部分对于两个Objective-完全相同C和Swif t版本看起来像这样:
The Info.plist NSExtension portion is exactly the same for both Objective-C and Swift version and looks like this:
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionPointName</key>
<string>com.apple.share-services</string>
<key>NSExtensionPointVersion</key>
<string>1.0</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
</dict>
我做错了什么?
推荐答案
致电
self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
在completionHandler结束时而不是在didSelectPost()
at the end of completionHandler instead of calling it at the end of didSelectPost()
这篇关于iOS 8共享扩展loadItemForTypeIdentifier:options:completionHandler:完成关闭未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!