检查iOS是否在应用程序上显示系统警报的可靠方法?(如定位服务等) [英] Reliable way to check if iOS is displaying a system alert over an app? (such as Location Services, etc.)

查看:22
本文介绍了检查iOS是否在应用程序上显示系统警报的可靠方法?(如定位服务等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 UIViewController 检查定位服务联系人权限提示是否在应用程序上可见?

Is there any way to check from a UIViewController whether or not the Location Services or Contacts permission prompts are visible over the application?

推荐答案

UIApplicationWillResignActive 方法在您描述的权限提示被触发时被触发.要监听这个,首先在你的控制器中添加一个监听器

The Method UIApplicationWillResignActive is triggered when a permissions prompt is triggered as you are describing. To listen for this, first add a listener to your controller

[[NSNotificationCenter defaultCenter]addObserver:self  selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];

然后,实现您在观察者中指定的选择器(本例中为willResignActive)

Then, implement the selector you specified in the observer (willResignActive in this case)

- (void)willResignActive {
  //Location services or contacts permission prompts may have been shown
}

请注意,不能保证这是由于权限提示而触发的.它也可能是由来电或短信、锁定屏幕、下拉通知等引起的.但是如果您知道您的提示应该在什么时间出现,您将知道它是否显示.

Please note, there is no guarantee that this was triggered because of the permissions prompts. It also could have been caused by an incoming phone call or text, a locked screen, pulling down notifications, etc. But if you know at what time your prompt should appear, you will have a good idea if it was shown or not.

最后一件事,确保你在 dealloc 方法中移除了你的观察者.

Last thing, make sure you remove your observer in the dealloc method.

- (void)dealloc {
      [[NSNotificationCenter defaultCenter]removeObserver:self name:UIApplicationWillResignActiveNotification object:nil];
}

如果您有任何问题,请告诉我.

Let me know if you have any questions.

这篇关于检查iOS是否在应用程序上显示系统警报的可靠方法?(如定位服务等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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