我正在使用
loadItemForTypeIdentifier:options:completionHandler: NSItemProvider 对象上的方法,用于通过 iOS 8 中的共享扩展从 Safari 中提取 url。
在 Objective-C 中,这段代码可以工作并且块也可以运行。
[itemProvider loadItemForTypeIdentifier:(@"public.url" options:nil completionHandler:^(NSURL *url, NSError *error) {
//My code
}];
在 Swift 中,它看起来非常相似,但是闭包不会运行。还,itemProvider.hasItemConformingToTypeIdentifier("public.url")
回报YES
所以必须有一个有效的对象来解析内部的urlitemProvider
.
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (urlItem, error) in
//My code
})
Info.plist NSExtension 部分对于 Objective-C 和 Swift 版本完全相同,如下所示:
<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>
我究竟做错了什么?
call
self.extensionContext!.completeRequestReturningItems([], completionHandler: nil)
在completionHandler的末尾,而不是在didSelectPost()的末尾调用它
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)