Adding UIPreviewActionItem to SFSafariViewController might be a tedious task. This extansion should help.
let vc = SFSafariViewController(initialURL: url, entersReaderIfAvailable: true)
vc.previewActionItemsDelegate = selfWhen presenting SFSafariViewController use convenience initializer that will store original URL for later, it'll make custom action requiring original URL easier. But it's not mandatory.
Here is the delegate implementation, this is where we might want to use initialURL
func safariViewControllerPreviewActionItems(controller: SFSafariViewController) -> [UIPreviewActionItem] {
var actions: [UIPreviewActionItem] = []
if let url = controller.initialURL {
// Only if we know initialURL
let action1 = UIPreviewAction(title: "Action 1", style: .Default, handler: { action, controller in
print("action1 for initial URL \(url)")
})
actions.append(action1)
}
let action2 = UIPreviewAction(title: "Action 2", style: .Default, handler: { action, controller in
print("action1")
})
actions.append(action2)
return actions
}
Do you have a way to do this through objective c? It looks great.