- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我已将 ABPeoplePickerNavigationController
添加到我的第一个 View Controller 中。我希望当我选择一个联系人时显示要在其他 View Controller 中显示的信息,但我正在尝试使用我的代码并且当我单击联系人时这不会显示。这只会将联系人打开到 native 应用 ABPeoplePickerNavigationController
。
var people = ABPeoplePickerNavigationController()
var addressBook: ABAddressBookRef?
func extractABAddressBookRef(abRef: Unmanaged<ABAddressBookRef>!) -> ABAddressBookRef? {
if let ab = abRef {
self.view.addSubview(people.view)
return Unmanaged<NSObject>.fromOpaque(ab.toOpaque()).takeUnretainedValue()
}
return nil
}
我试过这个功能
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!,didSelectPerson person: ABRecordRef!) {
var unmanagedEmails = ABRecordCopyValue(people, kABPersonEmailProperty)
let emailObj: ABMultiValueRef = Unmanaged.fromOpaque(unmanagedEmails.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef
var index = 0 as CFIndex
var unmanagedEmail = ABMultiValueCopyValueAtIndex(emailObj, index)
var emailAddress:String = Unmanaged.fromOpaque(unmanagedEmail.toOpaque()).takeUnretainedValue() as NSObject as String
println(emailAddress)
}
谢谢!
最佳答案
这是 iOS 9 的最新框架 - ContactsUI
导入联系人界面
符合 CNContactPickerDelegate (不需要方法)
创建一个联系人选择器对象并显示它:
let peoplePicker = CNContactPickerViewController()
peoplePicker.delegate = self
self.presentViewController(peoplePicker, animated: true, completion: nil)
在 contactPickerDidCancel 委托(delegate)函数中关闭 CNContactPickerViewController
func contactPickerDidCancel(picker: CNContactPickerViewController) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
以下是我如何使用 didSelectContact 委托(delegate)函数访问联系人姓名、电话号码、电话号码标签和照片:
func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
//Dismiss the picker VC
picker.dismissViewControllerAnimated(true, completion: nil)
//See if the contact has multiple phone numbers
if contact.phoneNumbers.count > 1 {
//If so we need the user to select which phone number we want them to use
let multiplePhoneNumbersAlert = UIAlertController(title: "Which one?", message: "This contact has multiple phone numbers, which one did you want use?", preferredStyle: UIAlertControllerStyle.Alert)
//Loop through all the phone numbers that we got back
for number in contact.phoneNumbers {
//Each object in the phone numbers array has a value property that is a CNPhoneNumber object, Make sure we can get that
if let actualNumber = number.value as? CNPhoneNumber {
//Get the label for the phone number
var phoneNumberLabel = number.label
//Strip off all the extra crap that comes through in that label
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("_", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("$", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("!", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("<", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString(">", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
//Create a title for the action for the UIAlertVC that we display to the user to pick phone numbers
let actionTitle = phoneNumberLabel + " - " + actualNumber.stringValue
//Create the alert action
let numberAction = UIAlertAction(title: actionTitle, style: UIAlertActionStyle.Default, handler: { (theAction) -> Void in
//Create an empty string for the contacts name
var nameToSave = ""
//See if we can get A frist name
if contact.givenName == "" {
//If Not check for a last name
if contact.familyName == "" {
//If no last name set name to Unknown Name
nameToSave = "Unknown Name"
}else{
nameToSave = contact.familyName
}
}else{
nameToSave = contact.givenName
}
// See if we can get image data
if let imageData = contact.imageData {
//If so create the image
let userImage = UIImage(data: imageData)
}
//Do what you need to do with your new contact information here!
//Get the string value of the phone number like this:
actualNumber.stringValue
})
//Add the action to the AlertController
multiplePhoneNumbersAlert.addAction(numberAction)
}
}
//Add a cancel action
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: { (theAction) -> Void in
//Cancel action completion
})
//Add the cancel action
multiplePhoneNumbersAlert.addAction(cancelAction)
//Present the ALert controller
self.presentViewController(multiplePhoneNumbersAlert, animated: true, completion: nil)
}else{
//Make sure we have at least one phone number
if contact.phoneNumbers.count > 0 {
//If so get the CNPhoneNumber object from the first item in the array of phone numbers
if let actualNumber = contact.phoneNumbers.first?.value as? CNPhoneNumber {
//Get the label of the phone number
var phoneNumberLabel = contact.phoneNumbers.first!.label
//Strip out the stuff you don't need
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("_", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("$", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("!", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString("<", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
phoneNumberLabel = phoneNumberLabel.stringByReplacingOccurrencesOfString(">", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
//Create an empty string for the contacts name
var nameToSave = ""
//See if we can get A frist name
if contact.givenName == "" {
//If Not check for a last name
if contact.familyName == "" {
//If no last name set name to Unknown Name
nameToSave = "Unknown Name"
}else{
nameToSave = contact.familyName
}
}else{
nameToSave = contact.givenName
}
// See if we can get image data
if let imageData = contact.imageData {
//If so create the image
let userImage = UIImage(data: imageData)
}
//Do what you need to do with your new contact information here!
//Get the string value of the phone number like this:
actualNumber.stringValue
}
}else{
//If there are no phone numbers associated with the contact I call a custom funciton I wrote that lets me display an alert Controller to the user
self.displayAlert("Missing info", message: "You have no phone numbers associated with this contact")
}
}
}
关于swift - 如何在 Swift 中使用 ABPeoplePickerNavigationController 选择联系人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25218399/
我想调出用户的地址簿,并使用新的 PeoplePicker Controller 对结果进行切片,以仅显示与特定术语匹配的结果。我看到 UIPeoplePickerNavigationControll
我的联系人列表在模拟器中完美显示。它获取电话号码并将其放入文本框中。所以我决定在我的 iPhone 上尝试一下,它实际上执行了我点击的东西。它会调用该号码,而不是将号码放入文本框中。代码如下: - (
有什么方法可以自定义 ABPeoplePickerNavController 数据源吗?我的意思是,我不需要从手机的地址簿中获取成员,而是需要它从数组中获取数据,例如在我的应用程序中。我将从服务器获取
您好,我有一个 ABPeoplePickerNavigationController,在创建时设置其导航栏隐藏。 peoplePickerController.navigationBar.hidden
联系人应用程序中有一个“添加即时消息”按钮。有一些预定义的,如 Skype、MSN、Facebook 等,但您可以添加自定义的。 但是,如果您添加自定义即时消息地址,并使用 ABPeoplePicke
我有一个核心数据堆栈,其中包含一个名为“客户端”的实体。每个客户端都有一个“addressBookID”属性,它指的是地址簿中个人记录的唯一ID。我目前正在使用 fetchedResultsContr
我想使用 ABPeoplePickerNavigationController 但我想自定义 View 。我想要一些联系人的附件图像,并且我想以不同于默认方式的方式对它们进行排序。有办法吗?还是我必须
在使用 ABPeoplePickerNavigationController 时,didSelecPerson 委托(delegate)将在用户选择一个人时被调用,然后 ABPeoplePickerN
Apple 提供了一个名为 PeoplePicker 的示例项目,它启动了一个仅包含具有电子邮件地址的联系人的 ABPeoplePickerNavigationController: ABPeople
我正在检查我的应用程序以消除所有内存泄漏,分析工具使用 abpeoplepickernavigationcontroller 发现了一个泄漏。 我知道这与复制方法有关?但不知道如何在编写时的位置和时间
我只在模拟器中遇到此崩溃。在真实设备上它可以正常工作和调试。(因此它不是太重要,但我正在做一个演示文稿,模拟器很方便。) - (BOOL)peoplePickerNavigationControlle
当使用 ABPeoplePickerNavigationController 时,加载和显示控件需要一些时间(~0.5 秒),这比其他弹出窗口的正常 react 时间要慢。 我的解决方案是将 Cont
我正在使用此代码在应用中显示联系人。 - (IBAction) selectContact:(id)sender { ABPeoplePickerNavigationController *p
几周来我一直在寻找解决方案,这让我几近绝望。 问题很简单: 通过 ABPeoplePickerNavigationController(作为 ModalView),应该选择一个人。 然后仅(例如)显示
我正在对 ABPeoplePickerNavigationController 进行子类化,我想知道如何隐藏正确的工具栏项“Cancel”? 我一直在寻找,但找不到合适的解决方案。 谢谢! 最佳答案
我正在使用 ABPeoplePickerNavigationController 由用户选择地址簿联系人。使用此代码隐藏按钮操作: ABPeoplePickerNavigationController
我想提示用户从地址簿中选择 1 个或多个人,但 ABPeoplePickerNavigationController 不允许这样做(这很讽刺,因为这是人 选择器,而不是人选择器)。 在我创建自己的 C
我在我的应用程序中将 ABPeoplePickerNavigationController 显示为选项卡。用户点击姓名,然后点击电子邮件地址,然后我对电子邮件地址执行一些操作。 之后,我希望他们选择的
我正在使用 ABPeoplePicker 显示联系人列表。 我想过滤此联系人列表,仅显示具有电子邮件地址的联系人。我该怎么做? 最佳答案 我需要它,所以我开始做类似的事情。查看https://gith
我最近将我的 iPhone 和 Xcode 从 iOS 6 升级到 iOS 8,并且遇到了从 ABPeoplePickerNavigationController 选择电话号码或电子邮件地址时执行“默
我是一名优秀的程序员,十分优秀!