Change avatar throw error
//Swift
if (ServicesManager.sharedInstance()?.loginManager.isConnected ?? false) {
let photo: UIImage = UIImage(named: "new-avatar")!
ServicesManager.sharedInstance()?.contactsManagerService.updateUser(withFields: ["photo": photo], withCompletionBlock: {
(error:Optional<Error>) in
if (error != nil) {
print(error.debugDescription)
} else {
// Do something once updated successfully
}
})
}
This part in docs says how to update user avatar. However app will crash with reason:
Terminating app due the uncaught exception 'NSInvalidArgumentException', reason:
-[_TtGcs26_SwiftDeferredNSDictionaryVs11AnyHashableP__$removeObjectForKey:]: unrecognized selector sent to instance
Did you forget update documentation?
-
Hello Patrik,
Yes the documentation is not updated. I will do it for next version, thanks for the feedback.
As a quick answer, you can use `updateUserAvatar` and `deleteUserAvatar` from `ContactsManagerService`. However in latest SDK 2.4.0, these methods are synchronous, it means you need to dispatch in background if you don't want to block the current thread.
In a future version, these methods are deprecated and will be replaced by ones with completion block to handle the response.
Nghia
-
Hello Patrik Spisak
It's kinda weird. If you have this log with the delete method, it means your user doesn't have a photo data yet (so not possible to delete). Maybe try to delete / update from Web or Rainbow iOS client first.
For the update, do you see log starting by "
Update avatar with url" ?
And for result "Avatar update API result"
Nghia
-
Also API does not returning avatar data back, always return nil
if servicesManager?.loginManager.isConnected ?? false {
guard let personalProfile:Contact = servicesManager?.myUser.contact else {
return
} print(personalProfile.photoData)
}This is error log
2022-06-09 14:46:20.456255+0200 DholRainbow[40047:3255113] [ContactsManagerService:3782] Could not get the avatar for contact Contact 0x282347720 : firstname 'P****k', lastname 'S****k', jid: b5842c98caf046b7a6f8a57a723b38f7@sandbox-all-in-one-rbx-prod-1.rainbow.sbg
Seems there is problem with server. I thought that maybe that URL is blocking by company firewall, but I could not access even from mobile data.
2022-06-09 14:46:20.409796+0200 DholRainbow[40047:3255113] [DownloadManager:581] performing request : GET https://cdn.sandbox.openrainbow.com/api/avatar/61e7fd2ccb6f357e7ae66b26?size=256&update=8c09577437c62050262a121cda31a172 sendsize 391
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://cdn.sandbox.openrainbow.com/api/avatar/61e7fd2ccb6f357e7ae66b26?size=256&update=8c09577437c62050262a121cda31a172, NSErrorFailingURLKey=https://cdn.sandbox.openrainbow.com/api/avatar/61e7fd2ccb6f357e7ae66b26?size=256&update=8c09577437c62050262a121cda31a172, _kCFStreamErrorDomainKey=12} -
I have also tried on sandbox and have exact same issue than you.
I have seen that the CDN server is used in the URL for sandbox to get avatar and it seems it's not working. So I need to fix it in the SDK. Sorry you don't have any workaround during that time.
Thank you for this report and for all these information!
Please sign in to leave a comment.
Comments
10 comments