Started allowing setting message handlers to nil for dead engines (flutter/engine#18428)
This commit is contained in:
@@ -677,9 +677,12 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
|
||||
- (void)setMessageHandlerOnChannel:(NSString*)channel
|
||||
binaryMessageHandler:(FlutterBinaryMessageHandler)handler {
|
||||
NSParameterAssert(channel);
|
||||
NSAssert(_shell && _shell->IsSetup(),
|
||||
@"Setting a message handler before the FlutterEngine has been run.");
|
||||
self.iosPlatformView->GetPlatformMessageRouter().SetMessageHandler(channel.UTF8String, handler);
|
||||
if (_shell && _shell->IsSetup()) {
|
||||
self.iosPlatformView->GetPlatformMessageRouter().SetMessageHandler(channel.UTF8String, handler);
|
||||
} else {
|
||||
NSAssert(!handler, @"Setting a message handler before the FlutterEngine has been run.");
|
||||
// Setting a handler to nil for a not setup channel is a noop.
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - FlutterTextureRegistry
|
||||
|
||||
@@ -47,6 +47,14 @@ FLUTTER_ASSERT_ARC
|
||||
}]);
|
||||
}
|
||||
|
||||
- (void)testNilSetMessageHandlerBeforeRun {
|
||||
id project = OCMClassMock([FlutterDartProject class]);
|
||||
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];
|
||||
XCTAssertNotNil(engine);
|
||||
XCTAssertNoThrow([engine.binaryMessenger setMessageHandlerOnChannel:@"foo"
|
||||
binaryMessageHandler:nil]);
|
||||
}
|
||||
|
||||
- (void)testNotifyPluginOfDealloc {
|
||||
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
|
||||
OCMStub([plugin detachFromEngineForRegistrar:[OCMArg any]]);
|
||||
|
||||
Reference in New Issue
Block a user