Я пытаюсь использовать CNContactVCardSerialization и читаю поле PHOTO
Если фотография BASE64, она работает
import UIKit
import Contacts
let str = "BEGIN:VCARD \n" +
"VERSION:3.0 \n" +
"N:Smith;John;Mr. \n" +
"PHOTO;ENCODING=b;TYPE=JPEG:VGVzdCBUZXN0IFRlc3QgVGVzdCBUZXN0 \n" +
"END:VCARD"
if let data = str.data(using: .utf8) {
let contacts = try CNContactVCardSerialization.contacts(with: data)
let contact = contacts.first!
print("name: \(contact.givenName)")
print("surname: \(contact.familyName)")
print("photo: \(String(describing: contact.imageData))")
print("thumb: \(String(describing: contact.thumbnailImageData))")
}
выход
name: John
surname: Smith
photo: Optional(24 bytes)
thumb: nil
Но когда фотография является URI, она не
import UIKit
import Contacts
let str = "BEGIN:VCARD \n" +
"VERSION:3.0 \n" +
"N:Smith;John;Mr. \n" +
"PHOTO;VALUE=uri:http://www.example.com/pub/photos/jqpublic.gif \n" +
"END:VCARD"
if let data = str.data(using: .utf8) {
let contacts = try CNContactVCardSerialization.contacts(with: data)
let contact = contacts.first!
print("name: \(contact.givenName)")
print("surname: \(contact.familyName)")
print("photo: \(String(describing: contact.imageData))")
print("thumb: \(String(describing: contact.thumbnailImageData))")
}
Выход
name: John
surname: Smith
photo: nil
thumb: nil
Я использовал пример поля PHOTO из https://tools.ietf.org/html/rfc2426#section-3.1.4