Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
import UIKit
class OpenUtils: NSObject {
private let selectedURL: URL
private let webViewController: LegacyWebViewController
init(url: URL, webViewController: LegacyWebViewController) {
self.selectedURL = url
self.webViewController = webViewController
}
func buildShareViewController() -> UIActivityViewController {
var activityItems: [Any] = [selectedURL]
let printInfo = UIPrintInfo(dictionary: nil)
printInfo.jobName = selectedURL.absoluteString
printInfo.outputType = .general
activityItems.append(printInfo)
let renderer = UIPrintPageRenderer()
renderer.addPrintFormatter(webViewController.printFormatter, startingAtPageAt: 0)
activityItems.append(renderer)
if let title = webViewController.pageTitle {
activityItems.append(TitleActivityItemProvider(title: title))
}
let shareController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
shareController.popoverPresentationController?.permittedArrowDirections = .up
shareController.completionWithItemsHandler = { activityType, completed, returnedItems, activityError in
if !completed {
return
}
// Make sure the pasteboard only has one url.
if let url = UIPasteboard.general.urls?.first {
UIPasteboard.general.urls = [url]
}
}
return shareController
}
}