[ios] ContactsUI에서 연락처의 수정 가능 여부를 확인하는 방법은 무엇인가요?
import Contacts
func isContactModifiable(contactIdentifier: String) -> Bool {
let store = CNContactStore()
do {
let contact = try store.unifiedContact(withIdentifier: contactIdentifier, keysToFetch: [CNContactGivenNameKey as CNKeyDescriptor, CNContactFamilyNameKey as CNKeyDescriptor, CNContactMiddleNameKey as CNKeyDescriptor])
if contact.isReadOnly {
return false
} else {
return true
}
} catch {
print("Error fetching contact: \(error)")
return false
}
}
위의 코드에는 CNContactStore
를 사용하여 연락처를 가져오고 수정 가능 여부를 확인하는 함수가 포함되어 있습니다. 코드를 실행하면 contact
객체의 isReadOnly
속성을 통해 연락처가 수정 가능한지 여부를 확인할 수 있습니다. 기타 속성 및 필드를 포함하여 수정 가능 여부를 확인할 때 사용하려는 연락처에 따라 keysToFetch
매개변수에 필요한 키를 전달해야 합니다.
더 자세한 정보는 Apple 공식 문서를 참조하세요.
위의 코드는 Swift로 작성된 Contacts 프레임워크를 사용하여 연락처의 수정 가능 여부를 확인하는 방법을 보여줍니다.