从多任务恢复时如何重启应用 [英] How to restart an app when resumes from multi-tasking

查看:103
本文介绍了从多任务恢复时如何重启应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我的应用程序依赖于Internet连接,并且每次从主屏幕打开该应用程序时,它都会使用可达性"进行检查,然后允许用户继续或告诉他们建立连接.但是,我的问题是,当应用程序从多任务恢复后,它会跳过初始视图控制器,并直接转到原来的位置.从多任务恢复后,有什么办法可以使我刷新或重新启动应用程序?

So my app relies on an internet connection and every time the app is opened from the home screen it checks using Reachability and then allows the user to continue or tells them to get connected. My issue however is that when the app is resumed from multitasking, it skips the initial view controller and goes straight to where they were. Is there any way in swift that I could get the app to refresh or restart when it is resumed from multi-tasking?

谢谢

编辑 使用此代码时:

let storyboard = UIStoryboard(name: "MainStoryboard", bundle: nil)
self.window.rootViewController = MainStoryboard.instantiateInitialViewController()

我得到预期的声明错误.

I get expected declaration error.

推荐答案

您可以设置根视图控制器,它将重新启动主VC.假设您使用情节提要:

You can set your root view controller and it will restart you main VC. Assuming your using a storyboard:

(自身是指您的AppDelegate)

迅速:

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
self.window.rootViewController = storyboard.instantiateInitialViewController()

Objective-C:

Objective-C:

self.window.rootViewController = [[UIStoryboard storyboardWithName:@"MyStoryboardName" bundle:nil] instantiateInitialViewController];

这篇关于从多任务恢复时如何重启应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆