Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Retrieving and Viewing Data from Parse.com Deleting Data from Parse.com

Boaz Keren Gil
Boaz Keren Gil
18,947 Points

Parse REST API

Hello, I'm trying to delete the files from the Parse database using REST API (complete delete).

This is the CURL code given at Parse website:

    curl -X DELETE \
        -H "X-Parse-Application-Id: <YOUR_APPLICATION_ID>" \
        -H "X-Parse-Master-Key: <YOUR_MASTER_KEY>" \
        https://api.parse.com/1/files/<FILE_NAME>

And this is my objective c code:

        PFFile *file = [self.selectedMessage objectForKey:@"file"];
        [self.selectedMessage deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error){
            if (error) {
                NSLog(@"%@ %@", error, [error userInfo]);
            } else {
                //Getting the unique file name attached to the selected message.

                NSURL *fileURL = [NSURL URLWithString:file.url];
                NSString *fileName = [NSString stringWithFormat:@"%@",fileURL.pathComponents[2]];

                //Creating the CURL request.
                NSString *urlString = [NSString stringWithFormat:@"https://api.parse.com/1/files/%@", fileName];
                NSURL *url = [[NSURL alloc] initWithString:urlString];
                NSMutableURLRequest *restAPI = [[NSMutableURLRequest alloc] initWithURL:url];
                [restAPI setHTTPMethod:@"DELETE"];
                [restAPI setValue:@"MY APP KEY" forHTTPHeaderField:@"X-Parse-Application-Id"];
                [restAPI setValue:@"MY MASTER KEY" forHTTPHeaderField:@"X-Parse-Master-Key"];
                NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:restAPI delegate:self startImmediately:YES];

            }
        }];

I've never done this before, and unfortunately there is no way to check if it worked on Parse.com

What do you think?

P.S. I have this annoying unused variable notification about *connection... even though I don't need to use it again right? once I initialize it, it runs.. Maybe I should add

[connection cancel] 

after this?

2 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

I don't know if you need to delete connection at the end, but I would think you could get onto the Parse-site and check to if they are there.

Boaz Keren Gil
Boaz Keren Gil
18,947 Points

I don't know if this code is working or not, and there is no way to check it on the Parse web interface.. By theory everything is implemented right? it should work? And should I add the connection cancel at the end?