从 App Delegate 调用 Storyboard 场景

Call Storyboard scene from app delegate

我想从 appDelegate 调用故事板场景[storyboard ID : MyScene]

我已经搜索并尝试了很多关于堆栈溢出的答案!!但找不到有效的解决方案。

我试过的其中一个代码,

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sc= (UIViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MyScene"];

[self.window.rootViewController presentViewController:sc animated:YES completion:nil];

尝试延迟调用此代码。

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ 

// Your code for presenting 

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController *sc= (UIViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MyScene"];

[self.window.rootViewController presentViewController:sc animated:YES completion:nil];

});