0

I'm trying to store objects in a local Parse datastore on the device itself. I get an error when retrieving the stored object: 'Method requires Pinning enabled.'

I've implemented 'Parse.enalbelLocalDatastore() in AppDelegate.swift. I tried to hard-code the object to be sure there was an object to retrieve.


let configuration = ParseClientConfiguration
        {
            $0.applicationId = "..."
            $0.clientKey = "..."
            $0.server = "..."

        }
        Parse.enableLocalDatastore()
        Parse.initialize(with: configuration)
...
func blancoUser() {
        let object = PFObject(className: "UserData")
        object["id"] = (UUID().uuidString)
        object["LoginName"] = "userName"
        object["PinCode"] = "00000"
        object["ScreenName"] = "test"
        object["YearOfBirth"] = 0

        object.pinInBackground()
    }
...

let query = PFQuery(className: "UserData")
        var users:[UserData] = [UserData]()

        query.fromLocalDatastore()
        query.findObjectsInBackground { (objects: [PFObject]?, error: Error?) in
            if let error = error {
                print(error.localizedDescription)
            } else if let objects = objects

I want to get the variable 'users' with the locally stored user objects. What am I missing? Or does the ParseLocalDatastore work differently in SwiftUI.

Tom Fox
  • 897
  • 3
  • 14
  • 34
JanR
  • 51
  • 3
  • Your blancoUser() method does not persist the record. Calling pinInBackground() does not persist the record. You should call the saveInBackground() on the new object. – Ian Bradbury Oct 29 '19 at 22:00

1 Answers1

0

Can you try to initialize the SDK like this?

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        let parseConfig = ParseClientConfiguration {
            $0.isLocalDatastoreEnabled = true
            $0.applicationId = parseApplicationId
            $0.clientKey = parseClientKey
            $0.server = parseServerUrlString
        }
        Parse.initialize(with: parseConfig)
  }
}

Reference: https://docs.parseplatform.org/ios/guide/#local-datastore

Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11
  • Thanks for the suggestion: this extra line made the error 'Method requires Pinning enabled.' disappear. However, there are no objects stored in the local database with the command 'object.pinInBackground()' – JanR Aug 15 '19 at 20:08
  • remove this line `object["id"] = (UUID().uuidString)` The ids are set in server side. You can't set your own ids. – Davi Macêdo Aug 15 '19 at 20:14
  • Unfortunately, this makes no difference. Print of the object after removing the id: object: { LoginName = userName; PinCode = 00000; ScreenName = test; YearOfBirth = 0; } It doesn't show up I the query: users: [] – JanR Aug 16 '19 at 17:06
  • In the code you send you are never setting the users var. Check the objects var inside the callback function. – Davi Macêdo Aug 17 '19 at 01:22