大家好我一直致力于iOS Swift中的应用程序,它可以导出一个可以/应该在iPhone和Android上导入的vcard。对于iPhone,vcard工作得很好,但对于Android,vcard不会导入。我使用以下代码来做到这一点。请看看,让我知道我做错了什么。
func textBasedVCard()-> Data?{
let imageString = self.imageData.base64EncodedString()
var string = "BEGIN:VCARD\nVERSION:3.0\n"
string += "N:\(self.name!);\nFN:\(self.name!)\nORG:\(self.company!)\nTITLE:\(self.title!)\nTEL;TYPE=WORK,VOICE:\(self.phone!)\nADR;TYPE=WORK:;;\(self.address!)\nNOTE:\(self.notes!)\nitem1.URL:\(self.web!)\nitem2.URL:\(self.blog!)\nitem3.URL:\(self.socialMedia1!)\nitem4.URL:\(self.socialMedia2!)\nitem5.URL:\(self.socialMedia3!)\nEMAIL;TYPE=PREF,INTERNET:\(self.email!)\nPHOTO;ENCODING=b;TYPE=JPEG:\(imageString)\nEND:VCARD"
print(string)
let utf8str = string.data(using: String.Encoding.utf8)
//utf8str?.base64EncodedStringWithOptions(NSData.Base64EncodingOptions(rawValue: 0))
if let base64Encoded = utf8str?.base64EncodedString(options: .init(rawValue: 0))
{
return Data(base64Encoded: base64Encoded)!
}
return nil
}