Domanda

I am using Parse. I have a PFFILE that I am retrieving using a Query. I need to save it, and i found that you normally use saveEventualy. But it doesn't support PFFile. So how can I turn the PFFile into a PFObject? Or else how save the image for offline? That's my code up to now:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];        
    [self GetImage];
}

- (void)enteredForeground:(NSNotification*) not
{
    [self GetImage];
}

-(void)GetImage
{    
    PFQuery *query = [PFQuery queryWithClassName:@"Image"];    
    [query getObjectInBackgroundWithId:@"4tmub1uxVd" block:^(PFObject *imageObject, NSError >*error)        
    {        
        if (imageObject) {                
            PFFile *imageFile = imageObject[@"image"];               
            [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {               
                if (data) {                        
                    UIImage *image = [UIImage imageWithData:data];                       
                    if (image) {                        
                        self.imageview.image = image;                       
                    }                        
                } else {                        
                    NSLog(@"Error fetching image file: %@", error);                        
                }                    
            }];                
        } else {                
           NSLog(@"Error fetching object: %@", error);                
       }                                               
    }];

}
È stato utile?

Soluzione

Parse has recently introduced a new method called local Data Store. It let's you store objects and files, update and retrieve them. Check out the documentation.

Blog Post

Documentation That doesn't exactly answer your question, but it will achieve what you want it to!

Altri suggerimenti

You can't convert a PFFile to a PFObject, but you don't need to. The Image PFObject class you're fetching in the code above has a property, with key image, that represents a PFFile. If you modify this, you'd save the parent object, which would save the updated file alongside it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top