iphone - startMonitoringForRegion 并不总是有效

标签 iphone objective-c ios ios5 location

我有一个需要使用 StartMonitoringForRegion 的应用程序。 当我将以下代码放入应用程序 didFinishLaunchingWithOptions 中时,它会起作用。

[loc startUpdatingLocation];
CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(21.456372,39.287972);
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:coord radius:200 identifier:@"C"];
[self.locationManager startMonitoringForRegion:region desiredAccuracy:50];

但是当我在另一个 View 中使用相同的代码时,它不起作用!! 我尝试使用以下代码在主线程上执行代码:

if (![NSThread isMainThread])
{
    [self performSelectorOnMainThread:@selector(MonitorRegion:) withObject:pr waitUntilDone:NO];
    return;
}

但是还是不行!

为什么代码会在 didFinishLaunchingWithOptions 中运行而不是在其他 View 中运行!

是否存在区域监视器可能无法工作的情况?

最佳答案

经过搜索和不同的尝试,我想出了解决办法。

只是为了让 didEnterRegion 和 didExitRegion 工作, View 必须始终可见并运行。

我将所有内容都移到了 appDelegate,现在它可以正常工作了。

关于iphone - startMonitoringForRegion 并不总是有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10723048/

相关文章:

IOS - 如何创建模糊背景的 Facebook react 栏?

ios - 无效的 Apple Watch 图标文件名必须匹配模式 "*<dimension>@<scale>x.png"

ios - 具有复杂布局、可变行高和自动布局的 UITableViewCell

iphone - UIDatePicker 非连续分钟

iphone - UITableView 的默认标题 View

ios - UIScrollview 不滚动 iOS

ios - 如何在没有用户交互的情况下在后台接收 iOS 通知

ios - 如何处理: UIActionSheet deprecated (iOS8) X UIAlertController not supported (iOS7)

iphone - 优化 UIScrollView 中的图像加载

ios - 选项卡栏图像在 Storyboard中显示良好,但在模拟器中显示不佳