我正在尝试在我的 Flutter 应用程序中嵌入 iOS PDFKit。以下是我的代码
public class PDFCustomView: NSObject, FlutterPlatformView {
let frame: CGRect
let viewId: Int64
init(_ frame: CGRect,viewId: Int64, args: Any?){
self.frame = frame
self.viewId = viewId
}
public func view() -> UIView {
let pdfView = PDFView(frame: frame)
if let path = Bundle.main.path(forResource: "studenthandbook2018", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
pdfView.document = pdfDocument
}
}
return PDFView()
}
}
public class PdfViewFactory: NSObject, FlutterPlatformViewFactory {
public func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?)
-> FlutterPlatformView {
return PDFCustomView(frame,viewId: viewId,args: args)
}
}
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let viewFactory = PdfViewFactory()
registrar(forPlugin: "iospdf").register(viewFactory, withId: "PDFIOSView")
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Run Code Online (Sandbox Code Playgroud)
我还包括
<key>io.flutter.embedded_views_preview</key>
<true/>
Run Code Online (Sandbox Code Playgroud)
在 info.plist
PDFView我没有返回,而是尝试返回UISLider,它在我的应用程序中正常工作,但 PDFkit 给出错误提示CoreGraphics PDF has logged an error. Set environment variabe "CG_PDF_VERBOSE" to learn more.
这是 Flutter 错误还是我做错了什么?
| 归档时间: |
|
| 查看次数: |
5904 次 |
| 最近记录: |