我想从XMPP获取用户头像图片,为此我做了:
let photoData: NSData = (self.xmppvCardAvatarModule?.photoDataForJID(XMPPJID.jidWithString(onlineBuddies[indexPath.row] as! String)))!
cell.avatarImage.image = UIImage(data: photoData)
但它会返回下一个错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
当我打印出来时:
XMPPJID.jidWithString(onlineBuddies[indexPath.row] as! String)
它打印了我的用户名,但整行返回nil:
self.xmppvCardAvatarModule?.photoDataForJID(XMPPJID.jidWithString(onlineBuddies[indexPath.row] as! String))
我该如何解决?
答案 0 :(得分:0)
我建议像这样使用:
[self.vCardTempModule fetchvCardTempForJID:[XMPPJID jidWithString:phoneNumber] ignoreStorage:YES];
并在委托
中处理照片- (void)xmppvCardTempModule:(XMPPvCardTempModule *)vCardTempModule
didReceivevCardTemp:(XMPPvCardTemp *)vCardTemp
forJID:(XMPPJID *)jid
{
NSString * base64OfImage = [[vCardTemp elementForName:@"PHOTO"]stringValue];
}
还有另一种方法从另一个Delegate接收UIImage对象,我建议看看有关vCard的文档
-(void)xmppvCardAvatarModule:(XMPPvCardAvatarModule *)vCardTempModule didReceivePhoto:(UIImage *)photo forJID:(XMPPJID *)jid