IOS 7 didEnterRegion did not receive a call at all

I am using the following code to monitor regions in my iOS application. It works great when I create an application on iOS6. When I create it on iOS7, didEnterRegion does not start.

// create and register an area with 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]]; 

// In AppDelegate.m

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

I also set the required background modes as "Application Registers for location updates" in my plist files.

Any ideas on what is missing for this feature to work on iOS7?

Thanks!

+6
source share
1 answer

Something that should work for both iOS 6 and 7 is to create a public method inside your class that conforms to the CLLocationManagerDelegate protocol, which tells itself to start monitoring the region. For instance:

 //LocationManagerClass.h @interface LocationManagerClass : NSObject {... other stuff in the interface file} - (void)beginMonitoringRegion:(CLRegion *)region; @end 

and then in

 //LocationManagerClass.m @interface LocationManagerClass () <CLLocationManagerDelegate> @end @implementation LocationManagerClass {... other important stuff like locationManager:didEnterRegion:} - (void)beginMonitoringRegion:(CLRegion *)region { [[CLLocationManager sharedManager] startMonitoringForRegion:region]; } @end 

So, in your case, you would call [appDelegate beginMonitoringRegion:region];

On the other hand, I would recommend NOT to enter the location control code in the application delegate. Although technically this will work, it is usually not a good design for such things. Instead, as in the example above, I would try to put it in my own location manager class, which is likely to be a single. This blog post gives some good support, so why don’t you put a ton of things into the app’s delegate: http://www.hollance.com/2012/02/dont-abuse-the-app-delegate/

0
source

Source: https://habr.com/ru/post/955683/


All Articles