如何在我的Swift ActivityViewController中包含一个Objective-C扩展?

我已经在我的浏览器应用程序中包含了1Password扩展名。

但是,我已经在我的应用程序上安装了iOS 8 Share Sheet(ActivityViewController),并且希望在使用它自己的分享表内包含1Password。 我的应用程序是在Swift中,但1Password在Objective-C中。

以下是我用于ActivityViewController的代码:

@IBAction func _shareButton(sender: UIButton) { var shareContent = _searchBar.text if let myWebsite = NSURL(string: "\(_searchBar.text)") { let objectsToShare = [myWebsite] let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil) if UIDevice.currentDevice().userInterfaceIdiom == .Pad { // The app is running on an iPad, so you have to wrap it in a UIPopOverController var popOver: UIPopoverController = UIPopoverController(contentViewController: activityVC) let rect = CGRect(origin: CGPoint(x: 559, y: 44), size: CGSize(width: 38, height: 32)) // if your "share" button is a UIBarButtonItem popOver.presentPopoverFromRect(rect, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true) } else { self.presentViewController(activityVC, animated: true, completion: nil) } } } 

这里是如何1Password扩展代码:

 @IBAction func onePasswordButton(sender: AnyObject) { OnePasswordExtension.sharedExtension().fillItemIntoWebView(self._webView, forViewController: self, sender: sender, showOnlyLogins: false, completion: {(Bool) in // error handling }) } 

我尝试在UIActivityViewController的applicationActivities部分中使用扩展的代码,但它不起作用(生成失败)。

是否有可能在ActivityViewController中有1Password扩展?

谢谢,

PastaCoder

我已经通过Github与AgileBits支持部门的Rad Azzouz联系过了(你可以在这里find详细的问题),我们设法解决了这个问题。

以下是用于具有1Password扩展名的ActivityViewController的代码。

 @IBAction func showShareSheet(sender: AnyObject) -> Void { var onePasswordExtension = OnePasswordExtension.sharedExtension() // Create the 1Password extension item. onePasswordExtension.createExtensionItemForWebView(self.webView, completion: {(extensionItem, error) -> Void in if extensionItem == nil { println("Failed to create an extension item: <%@>", error) return } // Initialize the 1Password extension item property self.onePasswordExtensionItem = extensionItem var activityItems: NSArray = [ self ]; // Add as many custom activity items as you please // Setting up the activity view controller var activityViewController = UIActivityViewController(activityItems: activityItems as [AnyObject], applicationActivities: nil) if sender.isKindOfClass(UIBarButtonItem) { self.popoverPresentationController?.barButtonItem = sender as! UIBarButtonItem } else if sender.isKindOfClass(UIView) { self.popoverPresentationController?.sourceView = sender.superview self.popoverPresentationController?.sourceRect = sender.frame } activityViewController.completionWithItemsHandler = {(activityType, completed, returnedItems, activityError) -> Void in if onePasswordExtension.isOnePasswordExtensionActivityType(activityType) { if (returnedItems.count > 0) { onePasswordExtension.fillReturnedItems(returnedItems, intoWebView: self.webView, completion: { (success, returnedItemsError) -> Void in if success == false { println("Failed to fill login in webview: <%@>", returnedItemsError) } }) } else { // Code for other custom activity types } } } self.presentViewController(activityViewController, animated: true, completion: nil) }) }