ios - 从后台检查
问题描述
我在 Android 上有一个 webview,它始终检查是否有互联网从后台返回,检查连接状态是否已更改,如果它处于脱机状态,则应用程序使用以下代码将用户发送到“重新连接并重试”屏幕:
protected void onResume() {
super.onResume();
mWebView.onResume();
if (isConnected(getApplicationContext())){
} else {
Intent i = new Intent(MainActivity.this, off.class);
startActivity(i);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
}
到目前为止,我已经为这个 webview 的 ios 制作了一个版本,但是当应用程序从后台返回时我无法重现这个检查,我如何在 ios swift 中重现这个“onresume”?(检查我已经拥有的连接状态的代码)
解决方案
在 AppDelegate 中使用以下方法:
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
print("Enter foreground")
}
推荐阅读
- c# - 在不同的、独立的对象上工作的 C# 任务,仍然会出现同步错误,为什么?
- react-native - 在图标旁边的 FlatList 中居中文本 - React Native
- c - 可以覆盖指向字符串的指针数组的值吗?
- ios - Swift:在从初始化程序返回之前,不会在所有路径上调用“super.init”?
- php - 推荐奖金计算两次
- javascript - firebase 和 Angular 7 中文档中的集合
- width - Fabric.js:以编程方式更新其尺寸后未渲染的部分 Line
- php - 开发中的 Symfony 4 资产响应错误,需要哪个 php 扩展?
- pandas - 如何获取一列的行,然后对 Pandas 中特定列中的行求和
- json - 通过“powershell”命令从 json 文件中提取数据