检查 GPS 警报是否存在

发布于 2025-01-08 12:15:35 字数 116 浏览 0 评论 0原文

我想检查我的窗口上是否已存在警报。该警报是 GPS 的警报(诸如“您的应用程序”之类的警报将使用您当前的位置以及“不允许”和“允许”按钮)。如果屏幕上出现此警报,我想设置一些标志。如果有人知道的话,请帮我解决这个问题。

I want to check if an alert is already present on my window or not. The alert is that of GPS (sumthing like "your app" will like to use your current location with Don't Allow and Allow buttons). I want to set some flag if this alert is present on screen. If anyone knows it, then please help me in getting this solved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江湖彼岸 2025-01-15 12:15:35
for (UIWindow* window in [UIApplication sharedApplication].windows) {
  NSArray* subviews = window.subviews;
  if ([subviews count] > 0)
    if ([[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]])
      return YES;
}
return NO;

这将有助于...

for (UIWindow* window in [UIApplication sharedApplication].windows) {
  NSArray* subviews = window.subviews;
  if ([subviews count] > 0)
    if ([[subviews objectAtIndex:0] isKindOfClass:[UIAlertView class]])
      return YES;
}
return NO;

this will help...

尛丟丟 2025-01-15 12:15:35

如果您正在针对ios4.2或更高版本进行开发,则可以使用CLLocationManager类的authorizationStatus

为此,您需要检查[CLLocationManagerauthorizationStatus]变量,如果其值为kCLAuthorizationStatusNotDetermined,那么将显示警报。

iOS 5或更高版本中,这是一个选项,用户可以通过该选项重置位置警告,在这种情况下,状态也将为kCLAuthorizationStatusNotDetermined。因此,如果您的应用程序正在运行并且用户切换到设置以重置该属性,那么您将需要实现以下 CLLocationManagerDelegate 委托方法。

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status)
    {
        case kCLAuthorizationStatusNotDetermined:
            //If this is the case than alert will be shown
            break;
        case kCLAuthorizationStatusDenied:

            break;
        case kCLAuthorizationStatusRestricted:

            break;
        case kCLAuthorizationStatusAuthorized:

            break;
        default:
            break;
    }

}

谢谢,

If you are developing for ios4.2 or later than you can authorizationStatus of CLLocationManager class.

For this you will need to check [CLLocationManager authorizationStatus] variable if its value is kCLAuthorizationStatusNotDetermined then it the alert will be shown.

In iOS 5 or later their is one option through which use can reset the location warning in that case also the status will be kCLAuthorizationStatusNotDetermined. So if your application is running and user switches to setting to reset that property than you will need to implmenet the following delegate method of CLLocationManagerDelegate.

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status)
    {
        case kCLAuthorizationStatusNotDetermined:
            //If this is the case than alert will be shown
            break;
        case kCLAuthorizationStatusDenied:

            break;
        case kCLAuthorizationStatusRestricted:

            break;
        case kCLAuthorizationStatusAuthorized:

            break;
        default:
            break;
    }

}

Thanks,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文