Iphone 核心位置DIDENTERE地区没有';行不通
仅当与实现CLLocationManagerDelegate的类对应的UIView处于活动状态时才有效 如果我改变了视图,它将不会触发DidEnter区域。有人能帮我吗 我的代码是这样的Iphone 核心位置DIDENTERE地区没有';行不通,iphone,ios,core-location,Iphone,Ios,Core Location,仅当与实现CLLocationManagerDelegate的类对应的UIView处于活动状态时才有效 如果我改变了视图,它将不会触发DidEnter区域。有人能帮我吗 我的代码是这样的 - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 从您的代码来看,我猜您正在使用ARC,这取决于您的控制器/视图层次结构,当您切换到其他视图时,您的视图和控制器可能会被解除分配,当这种情
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
从您的代码来看,我猜您正在使用ARC,这取决于您的控制器/视图层次结构,当您切换到其他视图时,您的视图和控制器可能会被解除分配,当这种情况发生时,locationManager也将被解除分配
只需将整个CLLocationManager代码移动到您的AppDelegate,并让AppDelegate成为CLLocationManager委托。在您现在调用“enableRegionMonitoring”的地方,您可以在AppDelegate上调用它。即使ViewController不再可见,它也将保持活动状态。您到底在看什么?因为如果要触发委托事件,必须为其设置委托。已设置委托[locationManager setDelegate:self];当我进入一个区域时,我想触发一个通知。请帮帮我。我真的被卡在上面了。这意味着区域内的便笺至少触发了一个吗?是的。如果与实现CLLocationManagerDelegate的类相对应的视图处于活动状态,则它将一直激发。但始终保持该视图处于活动状态是不可能的。
- (void)enableRegionMonitoring {
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
CLLocationCoordinate2D myMonLocation = CLLocationCoordinate2DMake(10.766699790955, 76.650101525879);
CLRegion *myRegion = [[CLRegion alloc]
initCircularRegionWithCenter:myMonLocation
radius:100
identifier:@"MyLoc"];
//NSLog(@"reg=%@",myRegion);
// Start monitoring for our CLRegion using best accuracy
[locationManager startMonitoringForRegion:myRegion
desiredAccuracy:kCLLocationAccuracyBest];
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
NSLog(@"Entered Region");
NSDate *nowx=[NSDate date];
UILocalNotification *localNotification=[[UILocalNotification alloc]init];
if (!localNotification)
return;
NSDictionary *data = [NSDictionary dictionaryWithObject:@"qw" forKey:@"mykey"];
[localNotification setUserInfo:data];
[localNotification setFireDate:nowx];
[localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
NSMutableString *message=[[NSMutableString alloc]init];
message = @"Local Not Triggered By didEnterRegion";
[localNotification setAlertBody:[nowx description]];
[localNotification setAlertAction:@"Open App"];
[localNotification setHasAction:YES];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}