iOS에서 지역 기반 알림을 구현하는 방법을 찾고 있습니다.
두 가지 방법을 찾았지만 어느 것이 가장 좋고 그 차이가 있는지 알아낼 수 없었습니다.iOS에서 이러한 지리적 기반 알림 접근 방식의 차이점은 무엇입니까?
1 : CLLocationManager의 startMonitoring 사용 이 자습서와 같습니다. https://www.raywenderlich.com/136165/core-location-geofencing-tutorial
2 : CLLocationManager의 startMonitoring 및 UILocalNotification 영역을 사용합니다. 이 코드처럼
:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.alertBody = [NSString stringWithFormat:@"Hello!"];
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
CLCircularRegion *region = nil;
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(geoPoint.latitude,
geoPoint.longitude);
if (CLLocationCoordinate2DIsValid(location)){
region = [[CLCircularRegion alloc] initWithCenter:location
radius:50.0
identifier:@"region1"];
region.notifyOnExit = NO;
localNotif.region = region;
localNotif.regionTriggersOnce = YES;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
} else {
NSDictionary *info = @{NSLocalizedDescriptionKey:@"Invalid coordinate info."};
NSError *error = [NSError errorWithDomain:@"InvalidCLLocationError"
code:1999
userInfo:info];
}