Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: await FlutterDownloader.initialize(); leads to google sign in cancel button crash #158

Closed
MunishThakur opened this issue Oct 31, 2019 · 16 comments

Comments

@MunishThakur
Copy link

iOS Only:
After initializing await FlutterDownloader.initialize(); in main() when google sign in popup appears and user press cancel.. APP Crashes.

Please look into.

This is very basic to use google sign in. Many users will face the same.

@hnvn
Copy link
Member

hnvn commented Oct 31, 2019

Try to modifying your AppDelegate like this:

@implementation AppDelegate

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

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  [FlutterDownloaderPlugin setPluginRegistrantCallback:registerPlugins];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

@MunishThakur
Copy link
Author

I have already modified AppDelegate like this and project running fine:

import UIKit
import Flutter
import Firebase
import flutter_downloader

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

private func registerPlugins(registry: FlutterPluginRegistry) {
GeneratedPluginRegistrant.register(with: registry)
}

The main issue is google_sign_in popup (Cancel or success result) leads to crash. Something wrong with
await FlutterDownloader.initialize();

@MunishThakur
Copy link
Author

Also in your documentation import flutter_downloader is missing. Please update doc

@hnvn
Copy link
Member

hnvn commented Oct 31, 2019

Have a look at this comment. FlutterDownloader.initialize() will start a background isolate, the plugin needs to register itself with FlutterEngine in this step but it uses a special instance of FlutterEngine that is served for background execution only. The snip codes in AppDelegate serve for this special registration:

private func registerPlugins(registry: FlutterPluginRegistry) {
   GeneratedPluginRegistrant.register(with: registry)
}

This default codes will execute the registration of all plugins in your project and if there's any plugins that requires UI manipulation, they will be broken in this step.

@MunishThakur
Copy link
Author

Thanks for the insight @hnvn. Issue is still the same. I just checked facebook login as well. When I click for facebook login It automatically lands to FacebookLoginStatus.cancelledByUser

This is really strange for me. No social login is working.

Without await FlutterDownloader.initialize(); works fine

@hnvn
Copy link
Member

hnvn commented Oct 31, 2019

Check my first comment again and notice this snip codes:

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

It's a modified version (from default one in document) for your case. It's Objective-C codes, you may as well translate it to Swift in your case.

@MunishThakur
Copy link
Author

Check my first comment again and notice this snip codes:

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

It's a modified version (from default one in document) for your case. It's Objective-C codes, you may as well translate it to Swift in your case.

Thanks swift version of above code worked for me. I already spent many hours, It saved many more :-)

Swift code:

private func registerPlugins(registry: FlutterPluginRegistry) {
//GeneratedPluginRegistrant.register(with: registry)
FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "vn.hunghd.flutter_downloader"))
}

@hnvn
Copy link
Member

hnvn commented Oct 31, 2019

Can you kindly share your full Swift codes of AppDelegate? I see the guys in this issue #149 still struggle with it.

@hnvn hnvn closed this as completed Oct 31, 2019
@MunishThakur
Copy link
Author

Complete AppDelegate swift code:


import UIKit
import Flutter
import Firebase
import flutter_downloader

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

private func registerPlugins(registry: FlutterPluginRegistry) {
    //GeneratedPluginRegistrant.register(with: registry)
    FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "vn.hunghd.flutter_downloader"))
}

@hnvn
Copy link
Member

hnvn commented Oct 31, 2019

Nice

@thesmalleyes
Copy link

Complete AppDelegate swift code:


import UIKit
import Flutter
import Firebase
import flutter_downloader

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

private func registerPlugins(registry: FlutterPluginRegistry) {
    //GeneratedPluginRegistrant.register(with: registry)
    FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "vn.hunghd.flutter_downloader"))
}

i've tried to use this in my appdelegate.swift. Butt my app is still crash after launch

@MunishThakur
Copy link
Author

Please share the log where it is crashing? My code was using facebook and some other libraries also which might be not necessary in your case.

Also Initialize it properly in main method.

@thesmalleyes
Copy link

this is my main method code

void main()async {
await FlutterDownloader.initialize();
// Pass all uncaught errors to Crashlytics.
FlutterError.onError = Crashlytics.instance.recordFlutterError;
runZoned<Future>(() async {
runApp();
}, onError: Crashlytics.instance.recordError);
}

i only got this message :

Crashlytics:Crash] Warning: NSUncaughtExceptionHandler is 'FBSDKExceptionHandler' in '/Users/bayuramadeza/Library/Developer/CoreSimulator/Devices/44000030-2E22-42F6-BF42-CC931D5BA3C9/data/Containers/Bundle/Application/F05047C6-5ECA-4EF8-BB38-A004FAE40411/Runner.app/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit'
[C7.1 68865C5A-3DC9-44D2-97CF-E68DAF006D64 192.168.1.12:61453<->157.240.13.14:443]
Connected Path: satisfied (Path is satisfied), interface: en0
Duration: 0.537s, DNS @0.002s took 0.002s, TCP @0.005s took 0.021s, TLS took 0.034s
bytes in/out: 4370/1559, packets in/out: 9/9, rtt: 0.024s, retransmitted packets: 0, out-of-order packets: 0
Lost connection to device.
Exited (sigterm)

@MunishThakur
Copy link
Author

"FBSDKExceptionHandler" is related with Facebook SDK. You must be sure if you have added FB sdk or if your app do not use FB SDK. Just remove FB related instances from your project.

firebase/quickstart-unity#486

Might help.

@thesmalleyes
Copy link

But, it’s running well if i don’t use flutter downloader,

@erperejildo
Copy link

Sorry, what's the solution here? I have the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants