0

I need to call the flutter engine all time .So I given the code as below.

In the appdelegate.h file

@property (nonatomic,strong) FlutterEngine *flutterEngine;

In the appdelegate.m file

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.flutterEngine = nil;

    //Flutter module initialization
    self.flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
    // Runs the default Dart entrypoint with a default Flutter route.
    [self.flutterEngine run];
    // Used to connect plugins (only if you have plugins with iOS platform code).
    [GeneratedPluginRegistrant registerWithRegistry:self.flutterEngine];
    
}

Then HomeVC.m file

 FlutterEngine *flutterEngine = ((IKAppDelegate *)UIApplication.sharedApplication.delegate).flutterEngine;
    
         if (flutterEngine != nil) {
     
         }
    
        flutterEngine = nil;
        flutterEngine = [[FlutterEngine alloc] initWithName:@"my flutter engine"];
        [flutterEngine  run];
        [GeneratedPluginRegistrant registerWithRegistry:flutterEngine];
        FlutterViewController *flutterViewController = [[FlutterViewController alloc]initWithEngine:flutterEngine nibName:nil bundle:nil];
        FlutterMethodChannel* moduleChannel = [FlutterMethodChannel
                                               methodChannelWithName:@"com.ikea.kompis/nativeToFlutter"
                                               binaryMessenger:flutterViewController.binaryMessenger];
        [moduleChannel invokeMethod:@"nativeToFlutter"
                          arguments: jsonString
        ];
       flutterViewController.modalPresentationStyle = UIModalPresentationFullScreen;
       // [self presentViewController:flutterViewController animated:YES completion:nil];

    [self presentViewController:flutterViewController animated:YES completion:nil];

But getting as crash. my flutter engine.3.profiler (52): EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

this can happen at any time .So how can fix this issuse

  • Hi, I removed the Swift tags because this is clearly an Objective-C question, not a Swift question. – JeremyP Oct 17 '22 at 10:00
  • is there any solution to solve this issuse – seena seena Oct 18 '22 at 05:32
  • What line does it crash on? – JeremyP Oct 18 '22 at 08:10
  • @JeremyP I have one button in that I have given this flutter function .When I clicked on that button at some time it get crash.Showing as :-my flutter engine.3.profiler (52): EXC_BAD_ACCESS ....May be 7 th time ..if on clicking 7 th time in the button ,it crash :-so it show as :- my flutter engine.7.profiler (52): EXC_BAD_ACCESS.So this crash happens at any time ...How can solve this issuse – seena seena Oct 18 '22 at 08:32
  • is there any solution to solve this issuse – seena seena Oct 18 '22 at 08:53
  • If it's crashing, it must be producing a stack trace. It's going to be really hard to diagnose the problem without knowing exactly which line of code generates the error. If you debug the app does it crash? If so that's the easiest way to get a stack trace. – JeremyP Oct 19 '22 at 08:47

0 Answers0