Hi guys ,
i’m creating an app users can sign in and create a group with multiple users in it that they can sharing a pictures or anything (the creator of the group is the admin or he can pass the administration to any one in the group) ? any idea how to do that ???
Hi Nasser,
How to do what?
- Create app?
Create group with multiple users?
Sharing pictures or anything?
Pass administration to any one?
Regards,
Mark
Hi Mark,
ok, How to Create group with multiple users?
here’s one way to do it:
http://support.backendless.com/public/attachments/8bfeed15907d15ceaae776e2999d5595.png</img>
thanks Mark very much for supporting
ok how to add a specific user to a specific group by Code Not the panal ?
Because in my app i’m trying to give any user the functionality to create a group and add some users in it for sharing photos or anything !
See the documentation: https://backendless.com/documentation/data/ios/data_relations_save_update.htm
so for each group i have to create a table ?
No, the UserGroup is already a table, for each group you will save an object in that table
Thanks Mark
i did it thanks to youhttp://support.backendless.com/public/attachments/2b450add0ba9f4debdfc619da59fe34e.png</img>
You got it, Nasser! Great job!
Hi Mark,
I’ve managed adding users very well with this Code
let User = userResults[indexPath.row]
let member1 = backendless.userService.findById(User.memberId)
let query = BackendlessDataQuery()
let group = backendless.persistenceService.of(Groups.ofClass()).find(query)
let currentPage = group.getCurrentPage()
for theGroup in currentPage as! [Groups] {
if theGroup.objectId == addNewUserGroup?.grouPId {
if theGroup.ownerId != member1.objectId {
theGroup.members.append(member1)
var error: Fault?
let result = backendless.data.update(theGroup, error: &error) as? Groups
if error == nil {
print("Member havs been added: \(result)")
} else {
print("Server reported an error: \(error)")
}
} else {
displayAlert("You are the owner of this group !", message: "")
print("He Is The Owner!")
}
}
}
BUT i’m struggling with delete users from the group … I’m trying with this code
let User = memberResult[indexPath.row]
let member = backendless.userService.findById(User.memberId)
let TheGroup = backendless.persistenceService.of(Groups.ofClass()).findID(groupUsersInfo?.grouPId) as! Groups
let index = TheGroup.members.indexOf(member)
TheGroup.members.removeAtIndex(index!)
var error: Fault?
let result = backendless.data.update(TheGroup, error: &error) as? Groups
if error == nil {
print("Member havs been updated: \(result)")
}
else {
print("Server reported an error: \(error)")
}
it give me this error …
http://support.backendless.com/public/attachments/83fa00ef5af555bf434163dac82badbe.png</img>
what is the problem ?
I do not know, it looks like a problem in your code and not with Backendless API. Use debugger to see where it does not work as expected.
Mark
so my delete users code is correct ?
it is, however, you need to make sure that the “members” collection is also returned. See the “Single Step Retrieval” section here:
https://backendless.com/documentation/data/ios/data_relations_retrieve.htm
Regards,
Mark