[ios] ContactsUI에서 연락처의 이메일 정보를 추가하는 방법은 무엇인가요?

ContactsUI 프레임워크는 iOS 앱에서 연락처 사전을 표시하고 편집하는 기능을 제공합니다. 이 중 이메일 정보를 추가하는 방법에 대해 알아보겠습니다.

1. 연락처 편집 뷰 컨트롤러 생성

먼저, ContactsUI 라이브러리를 import한 후, 연락처 편집 뷰 컨트롤러를 생성합니다.

import ContactsUI

let contactViewController = CNContactViewController(forNewContact: nil)
contactViewController.delegate = self
let navigationController = UINavigationController(rootViewController: contactViewController)
present(navigationController, animated: true, completion: nil)

2. 연락처에 이메일 정보 추가

연락처 편집 뷰 컨트롤러에서 다음 단계로 이메일 정보를 추가할 수 있습니다.

func contactViewController(_ viewController: CNContactViewController, shouldPerformDefaultActionFor property: CNContactProperty) -> Bool {
    if property.key == CNContactEmailAddressesKey {
        // 이메일 정보를 설정하는 뷰컨트롤러를 다음과 같이 호출
        let emailController = CNContactViewController(forNewContact: nil)
        emailController.contactStore = CNContactStore()
        emailController.delegate = self
        emailController.contact = property.contact
        emailController.displayingEmailAddress = true
        navigationController?.pushViewController(emailController, animated: true)
        return false
    }
    return true
}

이것으로 ContactsUI를 사용하여 연락처에 이메일 정보를 추가하는 방법에 대한 간략한 안내를 마치겠습니다. 필요에 따라 세부 구성을 조정하여 적용하시면 됩니다.

다양한 기능과 설정에 대한 자세한 내용은 Apple 공식 문서를 참고하시기 바랍니다.