[英]How can i detect [ in App-delegate ] that user changed view from standard to zoomed in Display settings of iphone
As much as i know when we switch between Standard and Zoomed view iphone restarts in background. 据我所知,当我们在标准视图和缩放视图之间切换时,iphone在后台重新启动。 I have some code in didFinishLaunchingWithOptions method for clearing keychain if its a fresh install. 我在didFinishLaunchingWithOptions方法中有一些代码,用于在全新安装时清除钥匙串。 Now when ever i switch view[standard to zoomed] iOs treats it as a fresh install and clears keychain, thus making my application crash. 现在,每当我将view [标准]切换到[缩放]时,iOS都会将其视为全新安装并清除钥匙串,从而使我的应用程序崩溃。 Is there anyway to know in code that view is changed so i can stop application from reseting keychain. 无论如何在代码中知道视图已更改,所以我可以阻止应用程序重置钥匙串。 Here is the code snippet: 这是代码片段:
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//clear keychain for every fresh install
if !Foundation.UserDefaults.standard.bool(forKey: Keys.kIsFreshInstall) {
//delete keychain
print("clearing keychain")
EMKeychainUtil.clearKeychain()
// update the flag indicator
Foundation.UserDefaults.standard.set(true, forKey:Keys.kIsFreshInstall)
}
return true
}
UPDATE: 更新:
Whenever device restarts UserDefaults are not reseted. 每当设备重启时,都不会重置UserDefaults。
There was a code in my project that was internally clearing the UserDefaults data first and then the check was made for keychain clearing , hence the issue was there. 我的项目中有一个代码,该代码首先内部清除UserDefaults数据,然后检查是否清除了钥匙串,因此问题就在那里。
In your appDelegate monitor UIScreen.mainScreen.nativeScale
property (not scale
) 在您的appDelegate监视器中, UIScreen.mainScreen.nativeScale
属性(不是scale
)
The. 的。 scale will remain constant but nativeScale will go up / down with the zoom factor set 比例将保持不变,但nativeScale将随着缩放系数的设置而上/下
— -
As for observing it: KVO would not work since any app is killed when changing zoom in settings. 至于观察:KVO将不起作用,因为更改缩放设置时会杀死任何应用程序。 You may have to persist it if needed 如果需要,您可能必须坚持下去
You can use the following code : 您可以使用以下代码:
[UIScreen mainScreen].scale
The scale size will be different when you changed from standard to zoomed. 从标准更改为缩放时,比例大小将有所不同。
Hope it will help! 希望对您有所帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.