Save method iOS SDK 4.0.7 not working

Hello, I’m having an issue with the save method.
Here’s the object I’m trying to save and the function.
The error completion handler of the save method is showing this error:
Optional(FAULT = ‘Server.Processing’ [exception during method invocation] <exception during method invocation> )

The app ID is “752CC57D-33EE-ADE7-FFC6-06A0D032FE00”

Thanks for the help

class Photo: NSObject {
 var objectId: String?
 var title: String?
 var location: GeoPoint?
 var imageUrl: String?
 var username: String?
 var datetime: Date?
 var address: String?
 var user: BackendlessUser?
 var isVideo: String?
 var videoThumbnail: String?
 var voiceNoteUrl: String?
}
//Backendless User
▿ Optional&lt;Dictionary&lt;String, Any&gt;>
 ▿ some : 17 elements
 ▿ 0 : 2 elements
 - key : "name"
 - value : Nelson B
 ▿ 1 : 2 elements
 - key : "email"
 - value : nelsonb21@gmail.com
 ▿ 2 : 2 elements
 - key : "__meta"
 - value : {"relationRemovalIds":{},"selectedProperties":["appVersion","website","created","bio","ownerId","__updated__meta","password","phoneModel","osVersion","name","osType","___class","updated","profileImageUrl","objectId","email"],"relatedObjects":{}}
 ▿ 3 : 2 elements
 - key : "___class"
 - value : Users
 ▿ 4 : 2 elements
 - key : "website"
 - value : google.com
 ▿ 5 : 2 elements
 - key : "ownerId"
 - value : E8E126E4-CCB6-A592-FFE5-F63A35C44100
 ▿ 6 : 2 elements
 - key : "osType"
 - value : iOS
 ▿ 7 : 2 elements
 - key : "lastLogin"
 - value : 2017-09-05 01:31:00 +0000
 ▿ 8 : 2 elements
 - key : "appVersion"
 - value : 1.0.1
 ▿ 9 : 2 elements
 - key : "profileImageUrl"
 - value : https://api.backendless.com/1e2a2619-c7dc-8017-ff81-11ea1bc91c00/v1/files/profileImages/E8E126E4CCB6A592FFE5F63A35C44100.png
 ▿ 10 : 2 elements
 - key : "bio"
 - value : IOS Developer
 ▿ 11 : 2 elements
 - key : "updated"
 - value : 2017-08-13 14:57:49 +0000
 ▿ 12 : 2 elements
 - key : "user-token"
 - value : 236623C2-BCD8-DBC9-FFB9-D0EBF5686A00
 ▿ 13 : 2 elements
 - key : "osVersion"
 - value : 10.3.3
 ▿ 14 : 2 elements
 - key : "created"
 - value : 2016-11-12 19:46:26 +0000
 ▿ 15 : 2 elements
 - key : "phoneModel"
 - value : iPhone 6s Plus
 ▿ 16 : 2 elements
 - key : "objectId"
 - value : E8E126E4-CCB6-A592-FFE5-F63A35C44100
//Location var value
"Optional(&lt;GeoPoint&gt; LAT:11.00597209173036, LON:-74.81811392779683, distance:0, CATEGORIES:(\n Bubo\n), METADATA:{\n}, objectId = (null))"
//Saving Function
static func savePhotoWithUser(_ photo: Photo, completion: @escaping AppCompletion) {
Backendless.sharedInstance().data.of(Photo.ofClass()).save(photo, response: { response in
 debugPrint(response as Any)
 completion(true, nil)
 return
 }, error: { (error) in
 debugPrint(error as Any)
 completion(false, error)
 return
 })
 }


Here is the async saving method with user relation which works fine:

func savePhoto() {
let photoStore = backendless.data.of(Photo.ofClass())!
let newPhoto = Photo()
newPhoto.title = "TEST PHOTO"
newPhoto.imageUrl = "NEW PHOTO IMAGE URL"
... other photo properties ....


photoStore.save(newPhoto,
                        response: {
                            savedPhoto in
                            let photo = savedPhoto as! Photo
                            let currentUser = self.backendless.userService.login("test@test.com", password: "111")!
                            photoStore.setRelation("user",
                                                   parentObjectId: photo.objectId,
                                                   childObjects: [currentUser.objectId],
                                                   response: {
                                                    response in
                                                    print("Relation set: \(response!)")
                            },
                                                   error: {
                                                    fault in
                                                    print(fault!.message)
                            })
        },
                        error: {
                            fault in
                            print(fault!.message)
        })

Regards, Olga

It is not working for me :frowning:

I’m still getting the error: FAULT = ‘Server.Processing’ [exception during method invocation] <exception during method invocation>

This is the method you posted implementation in my project

 
Backendless.sharedInstance().data.of(Photo.ofClass()).save(photo, response: { savedPhoto in 
 let photo = savedPhoto as! Photo 
 
 let currentUser = User.current 
 
 Backendless.sharedInstance().data.of(Photo.ofClass()).setRelation("user", parentObjectId: photo.objectId, childObjects: [currentUser.objectId], response: { response in 
 
 print("Relation set: \(response!)") 
 
 completion(true, nil) 
 
 return 
 
 }, error: { error in 
 
 debugPrint(error as Any) 
 
 completion(false, error) 
 
 return 
 
 }) 
 
 }, error: { error in 
 
 debugPrint(error as Any) 
 
 completion(false, error) 
 
 return 
 
 }) 



Hello,
We can’t reproduce this issue.
Could you please upload your project archive (only the part that causes issue: saving + completion) in Google Drive or Dropbox and share it with us (support@backendless.com)?

Regards, Olga

Hello,

I’m not able to provide the project.

I’m also getting the same error message trying to save in another table. Here is the class and the function.

FAULT = ‘Server.Processing’ [exception during method invocation] <exception during method invocation>

//Class LikePhoto
class LikePhoto: NSObject {




    var objectId: String?

    var user: BackendlessUser?

    var photo: Photo?

    

}
//Method
static func likePhoto(like: LikePhoto, completion: @escaping AppCompletion) {
        Backendless.sharedInstance().data.of(LikePhoto.ofClass())!.save(like, response: { response in
            debugPrint(response as Any)
            self.getLikes(with: User.current)
            completion(true, nil)
            return
        }, error: { (error) in
            debugPrint(error as Any)
            completion(false, error)
            return
        })












    }

I just manage to save a new record in the Photo Table.

The issue seems to be with the relations. I passed nil to booth var photo.user and photo.location and the record was saved.

Does this mean that for saving the relations between tables, they have to be done separately???

Thanks

Hello,

yes, you’re right. You need to save the relations separately.
Can I mark this topic as solved?

Regards, Olga

Sure mark it as solved.

But it would be really nice if this work as in the previous sdk version, where the relations where part of each class. This way the client only need to do one request, instead of the number of relations it has.

Thanks

I am totally agree with Nelson’s statement. I think the way the previous sdk version would be better for client side and reduce the code after the one request, and does not need to make more network requests. Please consider way back to old version regarding relation set.