iOSで地理情報ベースの通知を実装する方法を探しています。
私は2つの方法を見つけましたが、どちらが最良で違いがあるかわかりませんでした。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];
}