我已按照此question在浏览器应用中添加了1Password扩展程序。
但是,我已经在我的应用程序上安装了iOS 8共享表(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
部分使用扩展代码,但它不起作用(Build Failed)。
是否可以在ActivityViewController中包含1Password扩展名?
谢谢,
PastaCoder
答案 0 :(得分:0)
我通过Github联系了AgileBits支持部门的Rad Azzouz(你可以找到详细的问题here),我们设法解决了这个问题。
以下是用于具有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)
})
}