gpt4 book ai didi

ios - 在不添加联系人的情况下使用 CNContactViewController (swift)

转载 作者:搜寻专家 更新时间:2023-10-31 19:37:43 24 4
gpt4 key购买 nike

我想使用 contactsUI CNContactViewController.init(forNewContact: a) 仅用于查看并将值传递给服务器。但是,现在该功能还在地址簿/联系人应用程序中添加联系人,是否可以阻止这种情况?

最佳答案

联系人框架引用:https://developer.apple.com/library/ios/documentation/Contacts/Reference/Contacts_Framework/

sample: 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

关于ios - 在不添加联系人的情况下使用 CNContactViewController (swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38949454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com