diff --git a/ios/Classes/FlutterIsolatePlugin.m b/ios/Classes/FlutterIsolatePlugin.m index e344ad1..2d679af 100644 --- a/ios/Classes/FlutterIsolatePlugin.m +++ b/ios/Classes/FlutterIsolatePlugin.m @@ -20,6 +20,7 @@ @implementation IsolateHolder @interface FlutterIsolatePlugin() @property(nonatomic) NSObject * registrar; +@property(nonatomic) FlutterEngineGroup* engineGroup; @property(nonatomic) FlutterMethodChannel* controlChannel; @property FlutterEventSink sink; @end @@ -39,6 +40,8 @@ + (void)registerWithRegistrar:(NSObject*)registrar { FlutterIsolatePlugin *plugin = [[FlutterIsolatePlugin alloc] init]; plugin.registrar = registrar; + + plugin.engineGroup = [[FlutterEngineGroup alloc] initWithName:@"flutter_isolate" project:nil]; plugin.controlChannel = [FlutterMethodChannel methodChannelWithName:FLUTTER_ISOLATE_NAMESPACE @"/control" binaryMessenger:[registrar messenger]]; @@ -65,20 +68,21 @@ - (void)startNextIsolate { FlutterCallbackInformation *info = [FlutterCallbackCache lookupCallbackInformation:isolate.entryPoint]; - isolate.engine = [FlutterEngine alloc]; + isolate.engine = [self.engineGroup makeEngineWithEntrypoint:info.callbackName libraryURI:info.callbackLibraryPath]; + if ([isolate.engine respondsToSelector:@selector(initWithName:project:allowHeadlessExecution:)]) { + // use headless execution, if we can ((id(*)(id,SEL,id,id,id))objc_msgSend)(isolate.engine, @selector(initWithName:project:allowHeadlessExecution:) , isolate.isolateId, nil, @(YES)); - } - else // older versions before above is available + } else { + // older versions before above is available [isolate.engine initWithName:isolate.isolateId project:nil]; - + } /* not entire sure if a listen on an event channel will be queued * as we cannot register the event channel until after runWithEntryPoint has been called. If it is not queued * then this will be a race on the FlutterEventChannels initialization, and could deadlock. */ [isolate.engine runWithEntrypoint:info.callbackName libraryURI:info.callbackLibraryPath]; - isolate.controlChannel = [FlutterMethodChannel methodChannelWithName:FLUTTER_ISOLATE_NAMESPACE @"/control" binaryMessenger:isolate.engine];