diff --git a/doric-iOS/Pod/Classes/DoricContext.h b/doric-iOS/Pod/Classes/DoricContext.h index 69eedd61..4103d07c 100644 --- a/doric-iOS/Pod/Classes/DoricContext.h +++ b/doric-iOS/Pod/Classes/DoricContext.h @@ -33,6 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @interface DoricContext : NSObject @property(nonatomic, weak) id navigator; @property(nonatomic, weak) id navBar; +@property(nonatomic, weak) UIViewController *vc; @property(nonatomic, strong) NSString *contextId; @property(nonatomic, strong) id driver; @property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap; diff --git a/doric-iOS/Pod/Classes/DoricContext.m b/doric-iOS/Pod/Classes/DoricContext.m index dec4578a..9b1869c1 100644 --- a/doric-iOS/Pod/Classes/DoricContext.m +++ b/doric-iOS/Pod/Classes/DoricContext.m @@ -112,5 +112,10 @@ - (void)onShow { - (void)onHidden { [self callEntity:DORIC_ENTITY_HIDDEN withArgumentsArray:@[]]; } - +- (UIViewController *)vc { + if(!_vc) { + return [UIApplication sharedApplication].keyWindow.rootViewController; + } + return _vc; +} @end diff --git a/doric-iOS/Pod/Classes/DoricViewController.m b/doric-iOS/Pod/Classes/DoricViewController.m index f0dcb252..107d93ee 100644 --- a/doric-iOS/Pod/Classes/DoricViewController.m +++ b/doric-iOS/Pod/Classes/DoricViewController.m @@ -181,6 +181,7 @@ - (void)loadJSBundle { [self.doricPanel config:result alias:self.alias extra:self.extra]; self.doricPanel.doricContext.navigator = self; self.doricPanel.doricContext.navBar = self; + self.doricPanel.doricContext.vc = self; }); }; result.exceptionCallback = ^(NSException *e) { diff --git a/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m b/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m index bf0849a6..23a42503 100644 --- a/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m +++ b/doric-iOS/Pod/Classes/Plugin/DoricModalPlugin.m @@ -47,8 +47,7 @@ - (void)alert:(NSDictionary *)dic withPromise:(DoricPromise *)promise { [promise resolve:nil]; }]; [alert addAction:action]; - UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController; - [vc presentViewController:alert animated:YES completion:nil]; + [self.doricContext.vc presentViewController:alert animated:YES completion:nil]; }); } @@ -70,8 +69,7 @@ - (void)confirm:(NSDictionary *)dic withPromise:(DoricPromise *)promise { [promise reject:nil]; }]; [alert addAction:cancelAction]; - UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController; - [vc presentViewController:alert animated:YES completion:nil]; + [self.doricContext.vc presentViewController:alert animated:YES completion:nil]; }); } @@ -108,8 +106,7 @@ - (void)prompt:(NSDictionary *)dic withPromise:(DoricPromise *)promise { [alert addAction:cancelAction]; - UIViewController *vc = [UIApplication sharedApplication].keyWindow.rootViewController; - [vc presentViewController:alert animated:YES completion:nil]; + [self.doricContext.vc presentViewController:alert animated:YES completion:nil]; }); } @end