在iOS 10上无故调用applicationWillResignActive(swift 3) [英] applicationWillResignActive called without reason on iOS 10 ( swift 3 )

查看:74
本文介绍了在iOS 10上无故调用applicationWillResignActive(swift 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在iOS 10上启动我的应用程序时,可以看到在短暂的延迟之后,调用了Appdelegate函数-> applicationWillResignActive().没有任何理由.该应用程序在发生时仍处于活动状态并处于前台状态,并且该应用程序继续正常运行.

When I launch my app on iOS 10, I can see that after a short delay, the Appdelegate function -> applicationWillResignActive() is called. There is no reason for that. The app is still active and in foreground state when it occurs and the app continues to run normally.

请在我的应用的生命周期上方查看:

Please see above the lifecycle of my app :

->单击应用程序图标

  • 启动应用
  • 应用程序-> didFinishLaunchingWithOptions
  • 应用程序-> applicationDidBecomeActive
  • RootViewController-> viewDidAppear
  • 应用程序-> applicationWillResignActive<-问题!
  • 应用程序-> applicationDidBecomeActive<-再次?? !!
  • 此时,该应用仍在正常运行

每次我打开该应用程序时,都会重复此顺序.

This sequence is repeated each time I open the app.

似乎是某些因素迫使我的应用退出前台状态的时间极短.通常,当应用程序显示警报(例如,如果应用程序需要用户的权限才能访问相机)或用户单击主页"按钮时,就会调用applicationDidBecomeActive.

It looks as if something forces my app to quit the foreground state for an ultra short delay. Usually, applicationDidBecomeActive is called when the app displays an alert ( for example if the app requires an user's permission to access the camera ) or when the user clicks on the home button.

1-仅在应用以横向模式启动时发生
2-它仅在iPhone上发生,而不在iPad上发生
3-在iOS 9设备上不会发生该问题

1 - It only occurs when the app starts in landscape mode
2 - It only occurs on iPhones and not on iPads
3 - The problem does NOT occur on an iOS 9 device

有人注意到这个问题吗?

Did anyone noticed this problem ?

推荐答案

问题是,它在取消系统服务警报(位置,推送通知,照片)后第二次调用

The problem is, it calls second time after dismissing system services alert (location, push notifications, photos)

因此,处理此问题的唯一方法是在AppDelegate中使用变量,该变量每次在 applicationDidBecomeActive 中显示某些系统警报时会递增和递减,因此仅当此变量的值为1时才调用代码.

So the only way to handle it is to use variable in AppDelegate which increments each time some system alert shows and decrements in applicationDidBecomeActive, so you call your code only if value of this variable is 1.

另一个有趣的事情是,当系统警报显示时,不会调用 applicationDidEnterBackground ,因此我们可以使用此信息来决定是否应在 applicationDidBecomeActive 中调用我们的代码(但仍然是不太可靠的解决方案)

Another interesting thing is that applicationDidEnterBackground doesn't call when system alert shows, thus we can use this info to decide whether we should call our code in applicationDidBecomeActive or not (but still, it can be less reliable solution)

这篇关于在iOS 10上无故调用applicationWillResignActive(swift 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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