SomeOtherClass.m
AppDelegate appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];[appDelegate.locationManager startMonitoringForRegion:regionToMonitor desiredAccuracy:kCLLocationAccuracyNearestTenMeters];
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate,CLLocationManagerDelegate>@property (nonatomic,retain) CLLocationManager *locationManager;
AppDelegate.m
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ if (locationManager==nil) { locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; } return YES;}-(voID)locationManager:(CLLocationManager *)manager dIDEnterRegion:(CLRegion *)region { NSLog(@"DID enter region");}-(voID)locationManager:(CLLocationManager *)manager dIDExitRegion:(CLRegion *)region { NSLog(@"DID exit region");}-(voID)locationManager:(CLLocationManager *)manager dIDFailWithError:(NSError *)error { NSLog(@"Fail"); NSLog(@"%@",[error description]);}-(voID)locationManager:(CLLocationManager *)manager dIDStartMonitoringForRegion:(CLRegion *)region { NSLog(@"DID start monitoring for region: %@",region.IDentifIEr);}解决方法 首先,您应该添加以下位置管理器委托方法,并查看由于某种原因区域监视注册失败:
- (voID)locationManager:(CLLocationManager *)manager monitoringDIDFailForRegion:(CLRegion *)region withError:(NSError *)error { NSLog(@"%@",error);}
其次,区域监控是系统共享资源.
该文档指出,它允许您监控有限数量的区域(不幸的是不指定任何数字),并提到如果另一个应用程序注册要监控的其他区域,您的某些应用程序监控区域可能会被丢弃.
第三,区域监测没有使用任何GPS技术.它仅使用网络 *** 作符的蜂窝天线,无论何时更换蜂窝塔,它都会触发一个系统事件,该事件遍历所有受监控区域,并查看某个区域是否位于您现在所在的新区域内.
这意味着您应该期望服务的准确性降低,因此您应该增加为区域设置的半径.
最后,如果您的应用程序完全终止并且未被暂停,那么您的应用程序将在应用程序委托中接收:
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions
launchOptions字典中的UIApplicationLaunchOptionsLocationKey.
然后,您有责任在应用程序实时状态的有限时间内重新初始化您的位置管理器,获取当前位置并向用户发出本地推送通知.
由于应用程序不会在该阶段正常运行,但处于有限的后台模式状态.
此外,如果要在模拟器中测试应用程序,则应将track.gpx文件添加到项目中,并将模拟器设置为跟踪模式.确保放置在模拟器中的2个位置不是很远(因为完成跟踪可能需要很长时间)并将它们设置在路径中,它将进入受监控区域.然后看看你是否得到任何回调.不要使用您的设备进行测试,因为您需要实际走几个街区以查看与设备的任何真实交互:-)
总结以上是内存溢出为你收集整理的ios – 为什么我的CLLocationManager没有响应startMonitoringForRegion?全部内容,希望文章能够帮你解决ios – 为什么我的CLLocationManager没有响应startMonitoringForRegion?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)