Swift ABPEOPLEPICKERNAVIGATION控制器应在选择人员后继续
由于我将我的xcode 6版本更新为beta 3,我在AddressBookUI方面遇到了很多问题 阅读Apple API文档时,我看到了以下功能:Swift ABPEOPLEPICKERNAVIGATION控制器应在选择人员后继续,swift,addressbookui,Swift,Addressbookui,由于我将我的xcode 6版本更新为beta 3,我在AddressBookUI方面遇到了很多问题 阅读Apple API文档时,我看到了以下功能: func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecordRef!) -> Bool {} 在IOS 8中被弃用。如何将
func peoplePickerNavigationController(peoplePicker: ABPeoplePickerNavigationController!, shouldContinueAfterSelectingPerson person: ABRecordRef!) -> Bool {}
在IOS 8中被弃用。如何将此方法更新为正确的版本
在此方法中,我有以下代码:
var dadosContato: Dictionary<String, String> = ["firstName": "", "lastName": "","mobileNumber": "", "homeNumber": ""]
//NOME
var firstName: Unmanaged<AnyObject> = ABRecordCopyValue(person, kABPersonFirstNameProperty)
dadosContato["firstName"] = firstName.takeRetainedValue() as? String
//SOBRENOME
var lastName: Unmanaged<AnyObject> = ABRecordCopyValue(person, kABPersonLastNameProperty)
dadosContato["lastName"] = lastName.takeRetainedValue() as? String
//RECEBENDO OS TELEFONES
var phones: ABMultiValueRef = ABRecordCopyValue(person, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for var index = 0; index < ABMultiValueGetCount(phones); ++index{
let currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
let currentPhoneValue = ABMultiValueCopyValueAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
if currentPhoneLabel == kABPersonPhoneMobileLabel {
dadosContato["mobileNumber"] = currentPhoneValue
}
if currentPhoneLabel == kABHomeLabel {
dadosContato["homeNumber"] = currentPhoneValue
}
}
你有我没有的一半答案。 在手机中使用代码之前,您需要执行检查:
let phoneV: ABMultiValueRef = ABRecordCopyValue(record, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
if ABMultiValueGetCount(phoneV) > 0
{
var phones: ABMultiValueRef = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for var index = 0; index < ABMultiValueGetCount(phones); ++index{
let currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
let currentPhoneValue = ABMultiValueCopyValueAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
if currentPhoneLabel == kABPersonPhoneMobileLabel {
println(currentPhoneValue)
}
if currentPhoneLabel == kABHomeLabel {
println(currentPhoneValue)
}
}
}
让phoneV:ABMultiValueRef=ABRecordCopyValue(记录,kabbersonphoneproperty)。将unrepainedvalue()作为ABMultiValueRef
如果ABMultiValueGetCount(phoneV)>0
{
var phones:ABMultiValueRef=ABRecordCopyValue(contactPerson,KabbersonPhoneProperty)。将unrepainedValue()作为ABMultiValueRef
对于var index=0;index
我认为这是Swift编译器中的一个错误。我遇到了同样的问题。希望苹果能尽快修复它。一个临时的解决方法是用Objective-C编写通讯簿代码(并有一个返回数据结构的方法),然后Swift代码将调用该代码。选择Person后,该函数应继续?现在在ios 8上使用它的正确方法是什么?我在这里回答了这个问题:谢谢,你的解决方案适合我!!!!
let phoneV: ABMultiValueRef = ABRecordCopyValue(record, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
if ABMultiValueGetCount(phoneV) > 0
{
var phones: ABMultiValueRef = ABRecordCopyValue(contactPerson, kABPersonPhoneProperty).takeUnretainedValue() as ABMultiValueRef
for var index = 0; index < ABMultiValueGetCount(phones); ++index{
let currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
let currentPhoneValue = ABMultiValueCopyValueAtIndex(phones, index).takeUnretainedValue() as CFStringRef as String
if currentPhoneLabel == kABPersonPhoneMobileLabel {
println(currentPhoneValue)
}
if currentPhoneLabel == kABHomeLabel {
println(currentPhoneValue)
}
}
}