Ios7 iOS 7根本没有接到呼叫

Ios7 iOS 7根本没有接到呼叫,ios7,cllocationmanager,clregion,clcircleregion,Ios7,Cllocationmanager,Clregion,Clcircleregion,我正在使用以下代码监视iOS应用程序中的区域。当我在iOS6上构建应用程序时,它工作得非常好。当我在iOS7上构建它时,不会触发didEnterRegion //创建并向iOS注册区域 CLLocationCoordinate2D venueCenter = CLLocationCoordinate2DMake([favoriteVenue.venueLat doubleValue], [favoriteVenue.venueLng doubleValue]); CLRegion *r

我正在使用以下代码监视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和iOS 7都应该使用的方法是在类中创建一个公共方法,该方法符合
CLLocationManagerDelegate
协议,告知自己开始监视该区域。例如:

//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
//LocationManagerClass.m
@接口位置ManagerClass()
@结束
@实现位置ManagerClass
{…其他重要的东西,如locationManager:didEnterRegion:}
-(无效)开始监视区域:(CLRegion*)区域
{
[[CLLocationManager sharedManager]startMonitoringForRegion:region];
}
@结束
因此,在您的情况下,可以调用
[appDelegate beginMonitoringRegion:region]

另一方面,我建议不要将您的位置管理代码放在应用程序代理中。虽然从技术上讲它可以工作,但对于这样的事情,它通常不是一个好的设计模式。相反,在上面的例子中,我会尝试将它放在它自己的location manager类中,该类可能是一个单例。这篇博客文章对为什么不在app delegate中添加大量内容提供了很好的支持: