Creating and updating user with avatar

hi i would like to ask if there’s a way to create or update user with avatar using iOS Swift, just like in android… thanks!

1 Like

Hi,

is there a sample code that you can share with me?

hello @ordizrobert2011 ,

You can create user with avatar using below sample code snippet.

 let user = User(uid: "leona", name: "Leona Ryan")
 user.avatar = "https://randomuser.me/api/portraits/women/20.jpg"
        
    CometChat.createUser(user: user, apiKey: "API_KEY", onSuccess: { (user) in
            print("User created successfully: \(user.stringValue())")
     }) { (error) in
             print("User created failure: \(error?.errorDescription)")
      }
1 Like

@pushpsen.airekar thanks! i will try this and will let you know if it works! @pushpsen.airekar

@pushpsen.airekar thanks! it works fine… same with updateUser, right? i just need to set the avatar property… again, thanks!

1 Like

@ordizrobert2011,

Yes it would be the same with update user. I am sharing the sample code snippet for the same.

let user : User = User(uid: "leona", name: "Leona Ryan")
user.avatar = "https://image.shutterstock.com/image-photo/khonkaenthailand-march-4th-2017-batman-600w-622078991.jpg"
    CometChat.updateUser(user: user, apiKey: "API_KEY", onSuccess: { (user) in

        print("onSuccess: \(user)") 
    }) { (error) in
        
        print("failed: \(String(describing: error?.errorDescription))")
    } 

Do let us know if you have any other doubts.

2 Likes

@jeet.kapadia thanks! i works fine now…

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.