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

fix: iOS app crash when exit to background #625

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ios/Classes/FijkPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FijkPlugin *instance = [[FijkPlugin alloc] initWithRegistrar:registrar];
_instance = instance;
[registrar addMethodCallDelegate:instance channel:channel];
[registrar addApplicationDelegate:instance];
// For receiving detachFromEngineForRegistrar.
[registrar publish:instance];

FijkPlayer *player = [[FijkPlayer alloc] initJustTexture];
int64_t vid = [[registrar textures] registerTexture:player];
Expand Down Expand Up @@ -99,6 +102,24 @@ - (instancetype)initWithRegistrar:
return self;
}

// Called when a plugin is being removed from a FlutterEngine.
// See: https://github.com/flutter/engine/blob/e29263212bfdd3e51f8b1cd4b07dd60e2395d5bd/shell/platform/darwin/ios/framework/Headers/FlutterPlugin.h#L231-L242
- (void)detachFromEngineForRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
[self shutdownAllPlayers];
}

- (void)applicationWillTerminate:(UIApplication *)application {
[self shutdownAllPlayers];
}

- (void)shutdownAllPlayers {
for (NSNumber *pid in _fijkPlayers) {
FijkPlayer *fijkplayer = _fijkPlayers[pid];
[fijkplayer shutdown];
}
[_fijkPlayers removeAllObjects];
}

- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result {

Expand Down