Skip to content

deleteInBackgroundWithBlock Mac OS X #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomcoomer opened this issue Aug 24, 2015 · 32 comments
Closed

deleteInBackgroundWithBlock Mac OS X #100

tomcoomer opened this issue Aug 24, 2015 · 32 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Milestone

Comments

@tomcoomer
Copy link

I am using the code below that has previously worked to delete an object. However, after updating to the latest SDK, It no longer seems to be working. Any ideas?
Thanks

var query = PFQuery(className:"MyClass")
        query.getObjectInBackgroundWithId("myObjectId") {
            (gameScore: PFObject?, error: NSError?) -> Void in
            if error == nil && gameScore != nil {
                println(gameScore)
                gameScore!.deleteInBackgroundWithBlock({ (success, error) -> Void in
                    println("Deleted")
                })
            } else {
                println(error)
            }
        }
@nlutsenko
Copy link
Contributor

Go you see anything printed to the console?
It's hard to track this one down, since the code above works (just tested locally).

@nlutsenko nlutsenko self-assigned this Aug 24, 2015
@tomcoomer
Copy link
Author

The line:

println("Deleted")

Does print but when I log into Parse.com the object is still there.

@nlutsenko
Copy link
Contributor

Can you try reproducing the problem with curl and/or REST API? I suspect this to be a backend problem, since the client code finishes with some deterministic output.

Also based on your code - can you try printing the error that you get in the final closure? (deleteInBackground callback error).

@tomcoomer
Copy link
Author

I have printed out the Parse version and it printed version 1.8.0. I have updated to 1.8.1 and now the project won't build and shows the error below:

Warning: usage of --preserve-metadata with option "resource-rules" (deprecated in Mac OS X >= 10.10)!
/Users/name/Library/Developer/Xcode/DerivedData/AppName/Build/Products/Debug/AppName.app/Contents/Frameworks/Parse.framework/Versions/A: code object is not signed at all
In subcomponent: /Users/name/Library/Developer/Xcode/DerivedData/AppName/Build/Products/Debug/AppName.app/Contents/Frameworks/Parse.framework/Versions/A/Parse
Command /usr/bin/codesign failed with exit code 1

@nlutsenko
Copy link
Contributor

Based on the error message looks like you are missing Code sign on copy for Parse.framework.
Try adding it in build phase that copies your framework, then cleaning and building again.

@tomcoomer
Copy link
Author

The Code sign on copy Boxes are checked for both Parse.framework and Bolts.framework

@nlutsenko
Copy link
Contributor

Cleaning Xcode DerivedData I guess didn't help as well?
Last question, what is your method of installing the SDK: Cocoapods, directly from source, packages from releases? It's relevant to at least being able to identify the problem you are running in after the SDK is updated.

There was a bug change between 1.8 and 1.8.1 - the framework was renamed into Parse.framework instead of ParseOSX.framework. Would that be related to something you are running into?

The warning above simply says that code signing failed or that the copied framework inside your app is completely not code signed, but it should be.

@tomcoomer
Copy link
Author

I have downloaded the SDK from Parse.com then installed by dragging it into my Xcode Project. I Have also changed the Bridging Header form #import <ParseOSX/ParseOSX.h> to #import <Parse/Parse.h>

I have just deleted the Derived Data and built the project again but it has the same error.

@tomcoomer
Copy link
Author

Would using Cocoapods fix this issue?

@nlutsenko
Copy link
Contributor

Yup, that would help a lot.
I just reproduced the problem and I know the reason it's failing.
Cocoapods wouldn't have that problem.

@tomcoomer
Copy link
Author

I have just installed version 1.8.1 and I am having the same issue with the deleteInBackgroundWithBlock

@nlutsenko
Copy link
Contributor

Ok, one problem resolved - onto the next one.
Any chance you can print out the error from that last closure? (the completion of deleteInBackgroundWithBlock)

@tomcoomer
Copy link
Author

I am using println("Error: \(error?.localizedDescription)") and it prints Error: nil

Full code:

var query = PFQuery(className:"Layers")
        query.getObjectInBackgroundWithId("dWidTdCfy3") {
            (gameScore: PFObject?, error: NSError?) -> Void in
            if error == nil && gameScore != nil {
                println(gameScore)
                gameScore!.deleteInBackgroundWithBlock({ (success, error) -> Void in
                    println("Deleted")

                    println("Error: \(error?.localizedDescription)")

                })
            } else {
                println(error)
            }
        }

@nlutsenko
Copy link
Contributor

@tomcoomer Can you try reproducing the problem via curl request?
Also, just to confirm, this worked before 1.8.0 SDK and still works on that previous version?
Handy curl:

curl -X DELETE \
  -H "X-Parse-Application-Id: <YOURAPPID>" \
  -H "X-Parse-REST-API-Key: <YOURKEY>" \
  https://api.parse.com/1/classes/Layers/dWidTdCfy3

@tomcoomer
Copy link
Author

Sorry, do I run this in Terminal?
I have not used this before.
Thank you

@nlutsenko
Copy link
Contributor

Yup, paste this into terminal (replace with your keys first, though)

@tomcoomer
Copy link
Author

I have done that and it shows this: {"error":"unauthorized"}

@nlutsenko
Copy link
Contributor

Hmm... Are you sure you used the right keys (it's REST Key vs Client Key)?
That error says that keys used are wrong.
You can also see the exact same curl, but already adjusted for your request on https://parse.com/docs/rest/guide#objects-deleting-objects)

@tomcoomer
Copy link
Author

Sorry, I forgot to remove the < and > either side of the keys.
I ran it without < and > and it returned {} and the object has been deleted.

@nlutsenko
Copy link
Contributor

Definetly interested in whether this issue reproduce for a different object.
The fact that curl worked means that it's not a backend issue then.

@tomcoomer
Copy link
Author

Should I try it again for another object?

@nlutsenko
Copy link
Contributor

Yes, if that's not a hassle. Thank you!

@tomcoomer
Copy link
Author

I have tried deleting two more objects using Terminal and it has worked correctly, however using the Swift code it does not delete.

@nlutsenko
Copy link
Contributor

What would be printed with println("Error: \(error)")?
Maybe there is no localizedDescription, but the error is not-nil.

@tomcoomer
Copy link
Author

I have changed it to println("Error: \(error)" and it printed Error: nil

@tomcoomer
Copy link
Author

I have just tried println("Success: \(success)") and it prints Success: true. I don't know if this helps in any way?

@nlutsenko
Copy link
Contributor

I think I found the potential problem. And this is quite fascinating...
It looks like we are too agressively getting rid of object. If you continue to have the reference to the object until the end of the deleteInBackground operation - it will perform the operation with the object as it should, but otherwise it will simply ignore it, since object can be already gone from memory.

Submitting a fix for it in a few minutes, but in the meantime - could you try simply holding an object reference, say in ivar or referencing it once again inside the closure?

@tomcoomer
Copy link
Author

Using the code below deletes the object successfully:

    private var _object: PFObject?
    var object: PFObject? {
        get {
            return _object
        }
        set {
            _object = newValue
        }
    }

func delete() {
        var query = PFQuery(className:"Layers")
        query.getObjectInBackgroundWithId("jnbHTSYzZj") {
            (gameScore: PFObject?, error: NSError?) -> Void in
            if error == nil && gameScore != nil {
                println(gameScore)

                self._object = gameScore

                self._object!.deleteInBackgroundWithBlock({ (success, error) -> Void in
                    println("Deleted")

                    println("Error: \(error)")
                    println("Success: \(success)")

                })
            } else {
                println(error)
            }
        }
}

@nlutsenko
Copy link
Contributor

Woohoo! My theory was correct. Pull Request is coming to eliminate the requirements to use this at all.

@tomcoomer
Copy link
Author

Excellent! Will this version install using Cocoapods?

@nlutsenko
Copy link
Contributor

Yup. This will be included in 1.8.2, which is coming very soon.
You will also able to reference master from Cocoapods via

pod 'Parse', :git => 'https://github.com/parseplatform/parse-sdk-ios-osx.git' 

@nlutsenko nlutsenko added type:bug Impaired feature or lacking behavior that is likely assumed and removed needs repro labels Aug 24, 2015
@tomcoomer
Copy link
Author

That's great! Thank you for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants