[QBRequest signUp: user successBlock: ^ (QBResponse * response, QBUUser * user) {
// your file - this is an image in our case
NSData * imageData = UIImageJPEGRepresentation([UIImage imageNamed: @"Profile Picture"], 0.8 f);
[QBRequest TUploadFile: imageData fileName: @"ProfilePicture"
contentType: @"image/jpeg"
isPublic: YES successBlock: ^ (QBResponse * response, QBCBlob * blob) {
// File uploaded, do something
// if blob.isPublic == YES
NSString * url = [blob publicUrl];
}
statusBlock: ^ (QBRequest * request, QBRequestStatus * status) {
// handle progress
}
errorBlock: ^ (QBResponse * response) {
NSLog(@"error: %@", response.error);
}
];
我一直在尝试唱一个用户,并上传个人资料图片,但无法找到正确的方法。我是否必须将其上传到自定义数据或内容模块?我已经在CustomData中创建了一个字段。代码正在运行该文件正在某处保存,但我不知道在哪里。
我缺少什么,请帮助>即将疯狂>>>谢谢
答案 0 :(得分:7)
After you uploaded your picture (TUploadFile), in successBlock set [blob ID] to your QBUUser blobID property. After that just perform update user:
QBUpdateUserParameters *params = [QBUpdateUserParameters new];
params.blobID = [blob ID];
[QBRequest updateCurrentUser:params successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nullable user) {
// success block
} errorBlock:^(QBResponse * _Nonnull response) {
// error block
NSLog(@"Failed to update user: %@", [response.error reasons]);
}];
答案 1 :(得分:2)
Swift 4.2:
此答案适用于那些想要通过url(设置图片的网址)设置/获取用户个人资料图片的人
我们可以使用customData
类的QBUUser
属性。它将保留一个String
。
在注册时设置customData
。
let newUser = QBUUser()
newUser.login = "Saifan"
newUser.fullName = "Nadaf"
//Set your image url string here
newUser.customData = "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"
newUser.password = "Pass@1234"
QBRequest.signUp(newUser, successBlock: { [weak self] response, user in
guard let self = self else {
return
}
//SignUp Sucessfull Call Login Method Here
}, errorBlock: { [weak self] response in
response.status.rawValue == 422 {
// The User With Existent Login Was Created Earlier
// Call Login Method Here
return
}
})
如果我们想为现有用户设置/更新,我们可以使用QBUpdateUserParameters()
let updateUserParameter = QBUpdateUserParameters()
//Set ur Image URL to customData
updateUserParameter.customData = "https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"
//Use updateCurrentUser() to update user parameters
QBRequest.updateCurrentUser(updateUserParameter, successBlock: { [weak self] response, user in
guard let self = self else {
return
}
//*** This is Success Block ***//
//variable user is current updated User you can check on admin panel also
print("updated custom data \(user.customData)")
//Connect to chat using QBChat.instance.connect()
}, errorBlock: { [weak self] response in
//Handle Error Here
})
如果创建了对话框,则使用recipientID
类中的QBChatDialog
获取用户个人资料图像。
QBRequest.user(withID: UInt(chatDialog.recipientID), successBlock: { (res, user) in
if let imgUrl = user.customData {
// Here we will get imageUrl
print(imgUrl)
} else {
// Set Default image here
}
}) { (response) in }
使用customData
类中的QBUUser
获取用户个人资料图片
if let imgrUrl = user.customData{ // here user is a QBUUser()
// Here we will get imageUrl
print(imgUrl)
} else {
// Set Default image here
}
在管理面板上检查左侧->用户-> ID->