Current user path?

Hi. I’m trying to update a current user’s information. With new registrations, there is a Registration NSObject:


@interface Registration : NSObject


 self.registration = [Registration new];


 self.registration.path = uploadFile.fileURL;

How do yo do it when the user is already logged in? What will the NSObject be and what will replace “new” ?
For some reason:

-(IBAction)savePhoto:(id)sender {
 
 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
 
 NSString *fileName = [NSString stringWithFormat:@"profile/%0.0f.jpeg",[[NSDate date] timeIntervalSince1970] ];
 
 BackendlessFile *uploadFile = [backendless.fileService upload:fileName content:UIImagePNGRepresentation(self.profilePhoto.image)];
 self.imageURL = [uploadFile fileURL];
 
 [currentUser setProperty:@"photo" object:self.imageURL];
 
}

This uploads the photo just fine but it doesn’t set the property! The old photo remains!

Hi,

Line 10 changes only currentUser object, not its table record.To save changed user properties you should ‘update’ the user object , for example:

-(IBAction)savePhoto:(id)sender {


[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSString *fileName = [NSString stringWithFormat:@"profile/%0.0f.jpeg",[[NSDate date] timeIntervalSince1970] ];


@try {
BackendlessFile *uploadFile = [backendless.fileService upload:fileName         content:UIImagePNGRepresentation(self.profilePhoto.image)];
self.imageURL = [uploadFile fileURL];


BackendlessUser *currentUser = backendless.userService.currentUser;
[currentUser setProperty:@"photo" object:self.imageURL];


currentUser = [backendless.userService update:currentUser];
NSLog(@"(UPDATED) %@ ", currentUser);
   }  
@catch (Fault *fault) {
        NSLog(@"<SYNC> %@", fault);
  }
}

Pay attention to “try/catch” - you must use it with sync methods without ‘fault’ attribute to avoid a crash by “uncatched exception”.

That worked. Thank you so much :slight_smile: