gpt4 book ai didi

ios7 - iOS 7 didEnterRegion 根本没有被调用

转载 作者:行者123 更新时间:2023-12-04 16:10:37 28 4
gpt4 key购买 nike

我正在使用以下代码来监视我的 iOS 应用程序中的区域。当我在 iOS6 上构建应用程序时,它可以完美运行。当我在 iOS7 上构建它时,没有触发 didEnterRegion。

//在 iOS 中创建和注册一个区域

CLLocationCoordinate2D venueCenter = CLLocationCoordinate2DMake([favoriteVenue.venueLat      doubleValue], [favoriteVenue.venueLng doubleValue]);
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:venueCenter radius:REGION_RADIUS identifier:favoriteVenue.venueId];

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate.locationManager startMonitoringForRegion:[self regionForVenue:favoriteVenue]];

//在 AppDelegate.m 中
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"Entered region: %@", region.identifier);
}

我还在我的 plist 文件中将所需的后台模式设置为“应用程序注册位置更新”。

关于此功能在 iOS7 上工作缺少什么的任何想法?

谢谢!

最佳答案

应该适用于 iOS 6 和 7 的方法是在您的类中创建一个符合 CLLocationManagerDelegate 的公共(public)方法。告诉自己开始监视该区域的协议(protocol)。例如:

//LocationManagerClass.h

@interface LocationManagerClass : NSObject

{... other stuff in the interface file}

- (void)beginMonitoringRegion:(CLRegion *)region;

@end

然后在
//LocationManagerClass.m

@interface LocationManagerClass () <CLLocationManagerDelegate>
@end

@implementation LocationManagerClass

{... other important stuff like locationManager:didEnterRegion:}

- (void)beginMonitoringRegion:(CLRegion *)region
{
[[CLLocationManager sharedManager] startMonitoringForRegion:region];
}

@end

所以在你的情况下,你会调用 [appDelegate beginMonitoringRegion:region];
附带说明一下,我建议不要将您的位置管理代码放在应用程序委托(delegate)中。尽管从技术上讲它会起作用,但对于这样的事情,它通常不是一个好的设计模式。相反,在上面的示例中,我会尝试将它放在它自己的位置管理器类中,该类可能是一个单例。这篇博文提供了一些很好的支持,说明为什么不在应用程序委托(delegate)中放置大量内容: http://www.hollance.com/2012/02/dont-abuse-the-app-delegate/

关于ios7 - iOS 7 didEnterRegion 根本没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19300212/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com