contactsUI CNContactViewController.init(forNewContact: a)
을보기 전용으로 사용하여 서버에 값을 가져 오려고합니다. 그러나, 지금 func는 또한 주소록/연락처 응용 프로그램에 연락처를 추가, 이것을 방지 할 수 있습니까?연락처 추가없이 CNContactViewController 사용 (빠른)
3
A
답변
0
연락처 Framework 참조 : https://developer.apple.com/library/ios/documentation/Contacts/Reference/Contacts_Framework/
샘플 : ViewController.swift
import UIKit
import ContactsUI
class ViewController: UIViewController, CNContactPickerDelegate {
let contactPickerViewController = CNContactPickerViewController()
@IBOutlet var titleLabel: UILabel!
@IBOutlet var valueLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
contactPickerViewController.delegate = self
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func touchUpInside(sender: UIButton) {
self.presentViewController(contactPickerViewController, animated: true, completion: nil)
}
func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {
titleLabel.text = ""
valueLabel.text = ""
if let label = contactProperty.label {
titleLabel.text = CNLabeledValue.localizedStringForLabel(label)
}
if let phone = contactProperty.value as? CNPhoneNumber {
valueLabel.text = phone.stringValue
}
if let stringData = contactProperty.value as? String {
valueLabel.text = stringData
}
if let adress = contactProperty.value as? CNPostalAddress {
let adressString = adress.street + " " + adress.city + " " + adress.country + " " + adress.postalCode
valueLabel.text = adressString
}
}
}
다운로드 프로젝트 파일 : https://www.dropbox.com/s/yqdhqld0osp508b/Archive.zip?dl=0이
+0
이 솔루션은 도움이 되었습니까? –
당신이 이것에 대한 해결책을 찾았나요? – beseder
@beseder contactViewController 델리게이트를 사용할 때 done을 클릭하면 바로 CNcontact를 얻습니다. 따라서 해당 cncontact에서 식별자를 가져 와서 삭제합니다. ForNewContact 사용 -> 완료 -> 우리의 서버/응용 프로그램에 데이터를 보내십시오 -> 연락처를 프로그램 적으로 삭제하십시오 –
감사합니다! 그것이 내가 끝내었던 것입니다 :-) 그러나 그것은 나쁘다고 느낍니다. 그리고 무엇보다 : 그것은 실제로 필요하지 않은 사용자의 연락처에 대한 쓰기 액세스가 필요합니다. 따라서'CNContactViewController'의'contactStore' 속성은 문서화 된대로 행동하지 않습니다, 맞습니까? – beseder