Local Parse Database gives error in SwiftUI

126 Views Asked by At

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.

1

There are 1 best solutions below

4
Davi Macêdo On

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