Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
76b291a6
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
76b291a6
编写于
2月 05, 2020
作者:
G
gaaclarke
提交者:
GitHub
2月 05, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added a plugin method that gets called when the engine is about to be deleted (#16336)
上级
d5442b86
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
9 deletion
+55
-9
shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h
shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h
+13
-0
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
+29
-9
shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm
...platform/darwin/ios/framework/Source/FlutterEngineTest.mm
+13
-0
未找到文件。
shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h
浏览文件 @
76b291a6
...
...
@@ -223,6 +223,19 @@ typedef void (*FlutterPluginRegistrantCallback)(NSObject<FlutterPluginRegistry>*
* @param result A callback for submitting the result of the call.
*/
-
(
void
)
handleMethodCall
:(
FlutterMethodCall
*
)
call
result
:(
FlutterResult
)
result
;
@optional
/**
* Called when a plugin is being removed from a `FlutterEngine`, which is
* usually the result of the `FlutterEngine` being deallocated. This method
* provides the opportunity to do necessary cleanup.
*
* You will only receive this method if you registered your plugin instance with
* the `FlutterEngine` via `-[FlutterPluginRegistry publish:]`.
*
* @param registrar The registrar that was used to publish the plugin.
*
*/
-
(
void
)
detachFromEngineForRegistrar
:(
NSObject
<
FlutterPluginRegistrar
>*
)
registrar
;
@end
#pragma mark -
...
...
shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
浏览文件 @
76b291a6
...
...
@@ -29,19 +29,21 @@
NSString
*
const
FlutterDefaultDartEntrypoint
=
nil
;
@interface
FlutterEngineRegistrar
:
NSObject
<
FlutterPluginRegistrar
>
@property
(
nonatomic
,
assign
)
FlutterEngine
*
flutterEngine
;
-
(
instancetype
)
initWithPlugin
:(
NSString
*
)
pluginKey
flutterEngine
:(
FlutterEngine
*
)
flutterEngine
;
@end
@interface
FlutterEngine
()
<
FlutterTextInputDelegate
,
FlutterBinaryMessenger
>
// Maintains a dictionary of plugin names that have registered with the engine. Used by
// FlutterEngineRegistrar to implement a FlutterPluginRegistrar.
@property
(
nonatomic
,
readonly
)
NSMutableDictionary
*
pluginPublications
;
@property
(
nonatomic
,
readonly
)
NSMutableDictionary
<
NSString
*
,
FlutterEngineRegistrar
*>*
registrars
;
@property
(
nonatomic
,
readwrite
,
copy
)
NSString
*
isolateId
;
@property
(
nonatomic
,
retain
)
id
<
NSObject
>
flutterViewControllerWillDeallocObserver
;
@end
@interface
FlutterEngineRegistrar
:
NSObject
<
FlutterPluginRegistrar
>
-
(
instancetype
)
initWithPlugin
:(
NSString
*
)
pluginKey
flutterEngine
:(
FlutterEngine
*
)
flutterEngine
;
@end
@implementation
FlutterEngine
{
fml
::
scoped_nsobject
<
FlutterDartProject
>
_dartProject
;
flutter
::
ThreadHost
_threadHost
;
...
...
@@ -98,6 +100,7 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
_dartProject
.
reset
([
project
retain
]);
_pluginPublications
=
[
NSMutableDictionary
new
];
_registrars
=
[[
NSMutableDictionary
alloc
]
init
];
_platformViewsController
.
reset
(
new
flutter
::
FlutterPlatformViewsController
());
_binaryMessenger
=
[[
FlutterBinaryMessengerRelay
alloc
]
initWithParent
:
self
];
...
...
@@ -122,8 +125,24 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
}
-
(
void
)
dealloc
{
/// Notify plugins of dealloc. This should happen first in dealloc since the
/// plugins may be talking to things like the binaryMessenger.
[
_pluginPublications
enumerateKeysAndObjectsUsingBlock
:
^
(
id
key
,
id
object
,
BOOL
*
stop
)
{
if
([
object
respondsToSelector
:
@selector
(
detachFromEngineForRegistrar
:)])
{
NSObject
<
FlutterPluginRegistrar
>*
registrar
=
self
.
registrars
[
key
];
[
object
detachFromEngineForRegistrar
:
registrar
];
}
}];
/// nil out weak references.
[
_registrars
enumerateKeysAndObjectsUsingBlock:
^
(
id
key
,
FlutterEngineRegistrar
*
registrar
,
BOOL
*
stop
)
{
registrar
.
flutterEngine
=
nil
;
}];
[
_labelPrefix
release
];
[
_pluginPublications
release
];
[
_registrars
release
];
_binaryMessenger
.
parent
=
nil
;
[
_binaryMessenger
release
];
...
...
@@ -647,7 +666,10 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
-
(
NSObject
<
FlutterPluginRegistrar
>*
)
registrarForPlugin
:(
NSString
*
)
pluginKey
{
NSAssert
(
self
.
pluginPublications
[
pluginKey
]
==
nil
,
@"Duplicate plugin key: %@"
,
pluginKey
);
self
.
pluginPublications
[
pluginKey
]
=
[
NSNull
null
];
return
[[[
FlutterEngineRegistrar
alloc
]
initWithPlugin
:
pluginKey
flutterEngine
:
self
]
autorelease
];
FlutterEngineRegistrar
*
result
=
[[
FlutterEngineRegistrar
alloc
]
initWithPlugin
:
pluginKey
flutterEngine:
self
];
self
.
registrars
[
pluginKey
]
=
result
;
return
[
result
autorelease
];
}
-
(
BOOL
)
hasPlugin
:(
NSString
*
)
pluginKey
{
...
...
@@ -686,20 +708,18 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
@implementation
FlutterEngineRegistrar
{
NSString
*
_pluginKey
;
FlutterEngine
*
_flutterEngine
;
}
-
(
instancetype
)
initWithPlugin
:(
NSString
*
)
pluginKey
flutterEngine
:(
FlutterEngine
*
)
flutterEngine
{
self
=
[
super
init
];
NSAssert
(
self
,
@"Super init cannot be nil"
);
_pluginKey
=
[
pluginKey
retain
];
_flutterEngine
=
[
flutterEngine
retain
]
;
_pluginKey
=
[
pluginKey
copy
];
_flutterEngine
=
flutterEngine
;
return
self
;
}
-
(
void
)
dealloc
{
[
_pluginKey
release
];
[
_flutterEngine
release
];
[
super
dealloc
];
}
...
...
shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm
浏览文件 @
76b291a6
...
...
@@ -47,4 +47,17 @@ FLUTTER_ASSERT_ARC
}]);
}
-
(
void
)
testNotifyPluginOfDealloc
{
id
plugin
=
OCMProtocolMock
(
@protocol
(
FlutterPlugin
));
OCMStub
([
plugin
detachFromEngineForRegistrar
:[
OCMArg
any
]]);
{
id
project
=
OCMClassMock
([
FlutterDartProject
class
]);
FlutterEngine
*
engine
=
[[
FlutterEngine
alloc
]
initWithName
:
@"engine"
project
:
project
];
NSObject
<
FlutterPluginRegistrar
>*
registrar
=
[
engine
registrarForPlugin
:
@"plugin"
];
[
registrar
publish
:
plugin
];
engine
=
nil
;
}
OCMVerify
([
plugin
detachFromEngineForRegistrar
:[
OCMArg
any
]]);
}
@end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录