我正在SFSafariViewController
中打开一个pdf文件。现在,我要从SFSafariViewController
打印此PDF。
但是Safari浏览器视图控制器的“共享”按钮没有打印选项。
请告诉我如何向SFSafariViewController
添加打印功能。
答案 0 :(得分:0)
您可以自定义活动。
extension ViewController: SFSafariViewControllerDelegate {
func safariViewController(_ controller: SFSafariViewController, activityItemsFor URL: URL, title: String?) -> [UIActivity] {
let acitivity = CustomActivity()
return [acitivity]
}
func printURL(url: URL) {
}
}
CustomActivity.swift
import Foundation
import UIKit
class CustomActivity: UIActivity {
override class var activityCategory: UIActivityCategory {
return .action
}
override var activityType: UIActivityType? {
return UIActivityType.print
}
override var activityTitle: String? {
return "Print"
}
override var activityImage: UIImage? {
return nil
}
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
return true
}
override func perform() {
// do something here
}
}