Will Realm still be able to save the data while user has locked iPhone?


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]; } }


Doing something while the phone is locked is an example of a background task. Though I'm not sure if you will be successful in doing a task in the background even for once, but it is certain that when the OS kills your app, it can't do what you want to do any longer.

I'm doing in a project that is similar to yours (background location fetching, saving to local database the data, posting to the server while the screen is locked.) It is already complete but waiting for release signal. It was also submitted (approved) to the Apple as Beta.

I used this sample project as a library and ported to Swift:

<a href="https://github.com/voyage11/Location" rel="nofollow">https://github.com/voyage11/Location</a>


  • Weird locations from CLLocationManager in iOS9
  • Can Get Location, but not heading
  • Location alerts using Core Data to get around CLRegion 20 region cap
  • How to fetch current location in appdelegate using swift
  • iOS Core Location - Get MOST Accurate Location Coordinates
  • How to get timezone by latitude and longitude [duplicate]
  • Saving map pins to array, Swift
  • How can I add a UIToolbar to a UIViewController?
  • Load audio in DOCUMENTS when UITableView “cell” is pressed
  • Vertically stack an array of buttons using auto layout VFL
  • How can i get the locale from currency names list
  • Variable is not a static member of class
  • Convert NSDictionary to std::vector
  • How to load an NSDictionary from a file created with writeToFile?
  • Upload file onto Server from the IPhone using ASIHTTPRequest
  • how to get all installed applications with Objective C in OSX
  • Check if a UITableViewCell is completely visible
  • a simple person class in objective c
  • Why won't my UITableViewCell deselect and update its text?
  • How do display a UIAlertView from a block on iOS?
  • CFNetwork SSLHandshake failed (-9806) & (-9800) & (-9830)
  • Loopback validation on Properties who's types are other Models
  • NSMutableArray instance used in a block
  • How to pass solution folder as parameter in command line arguments (for debug)?
  • Using Sax parsing to edit and write XML in VB6
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • Saving Changes After In-App Purchase Has Been Purchased
  • QLPreviewController hide print button in ios6
  • Row Count Is Returning the incorrect number using RaptureXML
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Django: Count of Group Elements
  • javaw.exe and eclipse startup problems
  • Sending data from AppleScript to FileMaker records
  • MySQL WHERE-condition in procedure ignored
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal