diff --git a/README.md b/README.md index a643b558ca06bb0d9cba762b8191b45382e2c09d..682788286246c735559fe63915ff4913c2e2f560 100755 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ Initialize FlutterBoost with FLBPlatform at the beginning of your App. ```objc [FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router - onStart:^(FlutterViewController *fvc) { + onStart:^(id engine) { }]; ``` diff --git a/README_CN.md b/README_CN.md index df17ea706410048c401ea6320c16808dd91b2ff5..0043cf896ffe54b39d93a4b5875e6dbb1ed7a964 100755 --- a/README_CN.md +++ b/README_CN.md @@ -123,7 +123,7 @@ class _MyAppState extends State<MyApp> { ```的ObjectiveC [FlutterBoostPlugin.sharedInstance startFlutterWithPlatform:router - onStart:^(FlutterViewController * fvc){ + onStart:^(id engine){ }]; ``` diff --git a/ios/Classes/1.5/FLB2FlutterApplication.m b/ios/Classes/1.5/FLB2FlutterApplication.m index 12c2654cfba8f4c67edbd9a1a64195c1fc880328..4cded78addbfa31bd46b2eceec506ccbc3983620 100755 --- a/ios/Classes/1.5/FLB2FlutterApplication.m +++ b/ios/Classes/1.5/FLB2FlutterApplication.m @@ -76,13 +76,24 @@ _manager = [FLB2FlutterContainerManager new]; _pageResultCallbacks = NSMutableDictionary.new; _callbackCache = NSMutableDictionary.new; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationWillEnterForeground:) + name:UIApplicationWillEnterForegroundNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidEnterBackground:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; } return self; } - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; } - (UIView *)flutterView @@ -90,6 +101,13 @@ return [self flutterViewController].view; } +- (void)applicationDidEnterBackground:(UIApplication *)application { + [self.viewProvider didEnterBackground]; +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + [self.viewProvider willEnterForeground]; +} - (BOOL)contains:(id<FLBFlutterContainer>)vc { diff --git a/ios/Classes/1.5/FLB2FlutterEngine.m b/ios/Classes/1.5/FLB2FlutterEngine.m index 82b1d612d464f3dbb8e75b630b8f2b24f98c45b5..e0bf2c6cc3dc9c0f09944eca0abc1bdaa60295ee 100755 --- a/ios/Classes/1.5/FLB2FlutterEngine.m +++ b/ios/Classes/1.5/FLB2FlutterEngine.m @@ -25,6 +25,7 @@ #import "FLB2FlutterEngine.h" #import <Flutter/Flutter.h> #import "FLB2FlutterViewContainer.h" +#import "BoostMessageChannel.h" @interface FLB2FlutterEngine() @@ -87,6 +88,17 @@ } +- (void)didEnterBackground +{ + [BoostMessageChannel sendEvent:@"background" + arguments:nil]; +} + +- (void)willEnterForeground +{ + [BoostMessageChannel sendEvent:@"foreground" + arguments:nil]; +} - (FlutterEngine *)engine { diff --git a/ios/Classes/Boost/FLB2FlutterProvider.h b/ios/Classes/Boost/FLB2FlutterProvider.h index 2771bfc44bf91e84dea3c5e83add9e52078cb96e..8d3ede260e58455fc20d8d2286c5f05ead5e416f 100755 --- a/ios/Classes/Boost/FLB2FlutterProvider.h +++ b/ios/Classes/Boost/FLB2FlutterProvider.h @@ -37,5 +37,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)pause; - (void)resume; - (void)inactive; +- (void)didEnterBackground; +- (void)willEnterForeground; @end NS_ASSUME_NONNULL_END