I am trying to save some data to Ream database while users have locked their iPhone. Thie data may be the location coordinate which produced by background location updates. If realm can't do it. Could Core Data do it?
This is how I do it in code:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
NSLog(@"didUpdateLocations: %@", locations);
if (locations.count > 0) {
CLLocation *location = locations.firstObject;
if (location.horizontalAccuracy < 0) {
return;
}
JBLocation *locationObject = [[JBLocation alloc] init];
locationObject.lat = location.coordinate.latitude;
locationObject.lon = location.coordinate.longitude;
locationObject.date = [NSDate new];
locationObject.speed = location.speed;
RLMRealm *realm = [RLMRealm defaultRealm];
[realm beginWriteTransaction];
[realm addObject:locationObject];
[realm commitWriteTransaction];
}
}