From abc8e0cec09b750cd204553f199529ccde6672f7 Mon Sep 17 00:00:00 2001 From: anhhtbk Date: Mon, 16 Oct 2023 23:18:58 +0700 Subject: [PATCH] fix bug "A C function pointer can only be formed" --- README.md | 16 +++++++--------- example/ios/Runner/AppDelegate.swift | 10 ++++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fd0097a2..dfbe0d73 100644 --- a/README.md +++ b/README.md @@ -98,18 +98,16 @@ import flutter_downloader _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - GeneratedPluginRegistrant.register(with: self) - FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins) - return super.application(application, didFinishLaunchingWithOptions: launchOptions) + GeneratedPluginRegistrant.register(with: self) + FlutterDownloaderPlugin.setPluginRegistrantCallback { registry in + if (!registry.hasPlugin("FlutterDownloaderPlugin")) { + FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!) + } + } + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } -private func registerPlugins(registry: FlutterPluginRegistry) { - if (!registry.hasPlugin("FlutterDownloaderPlugin")) { - FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!) - } -} - ``` ### Optional configuration: diff --git a/example/ios/Runner/AppDelegate.swift b/example/ios/Runner/AppDelegate.swift index 70693e4a..9486bb2b 100644 --- a/example/ios/Runner/AppDelegate.swift +++ b/example/ios/Runner/AppDelegate.swift @@ -1,5 +1,6 @@ import UIKit import Flutter +import flutter_downloader @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { @@ -7,7 +8,12 @@ import Flutter _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { - GeneratedPluginRegistrant.register(with: self) - return super.application(application, didFinishLaunchingWithOptions: launchOptions) + GeneratedPluginRegistrant.register(with: self) + FlutterDownloaderPlugin.setPluginRegistrantCallback { registry in + if (!registry.hasPlugin("FlutterDownloaderPlugin")) { + FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!) + } + } + return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }