简体   繁体   English

如何检测[在App-Delegate中]用户将视图从标准更改为缩放到iPhone的显示设置

[英]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.

相关问题 在应用运行时,如何检测用户是否更改了iPhone系统语言设置? - How can I detect if a user has changed the iPhone system language settings while the app is running? 如何检测用户的 iPhone 6 Plus 是标准模式还是缩放模式? - How can I detect whether a user has an iPhone 6 Plus in standard or zoomed mode? 从App-delegate重新加载或运行功能 - reload or run function from App-delegate 在iOS中检测用户是否通过应用设置从Facebook删除了他的应用或更改了密码 - In iOS Detect whether user removed his app from Facebook via app settings or changed password 如何在没有缩放模式的iPhone 6上显示iOS应用程序 - How to display iOS app on iPhone 6 without zoomed mode iOS app-delegate方法耗时超过17秒 - iOS app-delegate method taking more than 17 sec 如果用户放大或缩小视图,如何区分? - How to differentiate if user zoomed in or zoomed out on view? 如何使用 InAppSettingsKit 委托重新配置更改的应用程序设置 - How to use InAppSettingsKit delegate to reconfigure changed app settings swift 3 检查 iphone 6/7 和 6/7plus 显示器是否处于标准或缩放模式 - swift 3 check if iphone 6/7 and 6/7plus display is in standard or zoomed mode 如何在应用程序运行之间本地检测用户的iPhone时钟进度? - How can I locally detect iPhone clock advancement by a user between app runs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM