question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to set registerPlugins on iOS

See original GitHub issue

Hi! I’m having a problem running an app with this plugin installed. I’ve done everything I found on the internet and nothing works… If I comment await FlutterDownloader.initialize(); I can start the application.

Exception:

[   +2 ms] [DEVICE LOG] 2020-01-09 10:10:13.600816+0100  localhost Runner[14546]: methodCallHandler: initialize
[        ] [DEVICE LOG] 2020-01-09 10:10:13.601151+0100  localhost Runner[14546]: startBackgroundIsolate
[        ] [DEVICE LOG] 2020-01-09 10:10:13.639051+0100  localhost Runner[14546]: (Foundation) *** Assertion failure in -[FlutterDownloaderPlugin startBackgroundIsolate:], /Users/breakpoint/Flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.3.4/ios/Classes/FlutterDownloaderPlugin.m:117
[        ] [DEVICE LOG] 2020-01-09 10:10:13.686382+0100  localhost Runner[14546]: (CoreFoundation) *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'failed to set registerPlugins'
[        ] [DEVICE LOG] *** First throw call stack:
[   +4 ms] [DEVICE LOG] (
[        ] [DEVICE LOG]         0   CoreFoundation                      0x000000010a5828db __exceptionPreprocess + 331
[        ] [DEVICE LOG]         1   libobjc.A.dylib                     0x0000000109437ac5 objc_exception_throw + 48
[        ] [DEVICE LOG]         2   CoreFoundation                      0x000000010a582662 +[NSException raise:format:arguments:] + 98
[        ] [DEVICE LOG]         3   Foundation                          0x0000000108b0d76b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
[        ] [DEVICE LOG]         4   Runner                              0x0000000105e50cfe -[FlutterDownloaderPlugin startBackgroundIsolate:] + 782
[        ] [DEVICE LOG]         5   Runner                              0x0000000105e569eb -[FlutterDownloaderPlugin initializeMethodCall:result:] + 187
[        ] [DEVICE LOG]         6   Runner                              0x0000000105e5a7d0 -[FlutterDownloaderPlugin handleMethodCall:result:] + 256
[        ] [DEVICE LOG]         7   Flutter                             0x0000000106a98f95 __45-[FlutterMethodCha<…>
[  +16 ms] methodCallHandler: initialize
[        ] startBackgroundIsolate
[        ] *** First throw call stack:
[        ] (
[        ]      0   CoreFoundation                      0x000000010a5828db __exceptionPreprocess + 331
[        ]      1   libobjc.A.dylib                     0x0000000109437ac5 objc_exception_throw + 48
[        ]      2   CoreFoundation                      0x000000010a582662 +[NSException raise:format:arguments:] + 98
[        ]      3   Foundation                          0x0000000108b0d76b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
[        ]      4   Runner                              0x0000000105e50cfe -[FlutterDownloaderPlugin startBackgroundIsolate:] + 782
[        ]      5   Runner                              0x0000000105e569eb -[FlutterDownloaderPlugin initializeMethodCall:result:] + 187
[        ]      6   Runner                              0x0000000105e5a7d0 -[FlutterDownloaderPlugin handleMethodCall:result:] + 256
[        ]      7   Flutter                             0x0000000106a98f95 __45-[FlutterMethodCha<…>
[   +3 ms] Service protocol connection closed.
[        ] Lost connection to device.

main.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await FlutterDownloader.initialize();

  ...
}

AppDelegate.m:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#include "FlutterDownloaderPlugin.h"

@implementation AppDelegate

void registerPlugins(NSObject<FlutterPluginRegistry>* registry) {
    [FlutterDownloaderPlugin registerWithRegistrar:[registry registrarForPlugin:@"vn.hunghd.flutter_downloader"]];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    if (@available(iOS 10.0, *)) {
        [UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>)self;
    }

    [GeneratedPluginRegistrant registerWithRegistry:self];
    [FlutterDownloaderPlugin setPluginRegistrantCallback:registerPlugins];

    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@end

flutter doctor:

[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.13.6 17G10021,
    locale en-BA)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 10.3)
[✓] Android Studio (version 3.3)
[✓] IntelliJ IDEA Community Edition (version 2019.3.1)
[✓] Connected device (1 available)

• No issues found!

flutter_downloader version:

1.3.4

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
y-sihyeoncommented, Feb 12, 2020

@anisalibegic check your “/ios/Runner/AppDelegate.swift” file. I had the same problem. I solved it by adding the code below.

“AppDelegate.swift”

import UIKit
import Flutter
import flutter_downloader

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

private func registerPlugins(registry: FlutterPluginRegistry) {
    if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
       FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin"))
    }
}

good luck!!

8reactions
bhargavsejpalindianiccommented, May 30, 2020

@anisalibegic check your “/ios/Runner/AppDelegate.swift” file. I had the same problem. I solved it by adding the code below.

“AppDelegate.swift”

import UIKit
import Flutter
import flutter_downloader

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

private func registerPlugins(registry: FlutterPluginRegistry) {
    if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
       FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin"))
    }
}

good luck!!

A C function pointer can only be formed from a reference to a ‘func’ or a literal closure

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting NSInternalInconsistencyException crash after Xcode ...
After upgrading my build environment to Xcode 12 and iOS 14 my application has begun crashing with the following error: ...
Read more >
Flutter: Tried to automatically register plugins with ...
Yeah, had similar error few days ago, when I implemented facebook login in ios and then I wanted to create android app from...
Read more >
flutter_downloader - Dart API docs - Pub.dev
A plugin for creating and managing download tasks. Supports iOS and Android. This plugin is using WorkManager on Android and NSURLSessionDownloadTask on iOS...
Read more >
Custom Native Android Code | Capacitor Documentation
First, create a EchoPlugin.java file by opening Android Studio, ... In JS, we use registerPlugin() from @capacitor/core to create an object which is...
Read more >
SoundJS v1.0.0 API Documentation : Sound - CreateJS
As a result, it may fail to play the first time play is called if the audio is not ... Set the preventSelection...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found