ABPeoplePickerNavigationController shouldContinueAfterSelectingPerson 已弃用 Swift

Posted

技术标签:

【中文标题】ABPeoplePickerNavigationController shouldContinueAfterSelectingPerson 已弃用 Swift【英文标题】:ABPeoplePickerNavigationController shouldContinueAfterSelectingPerson deprecated Swift 【发布时间】:2014-07-20 21:09:52 【问题描述】:

自从我将我的 xcode 6 版本更新到 beta 3 后,我在使用 AddressBookUI 时遇到了很多麻烦。

阅读 Apple API 文档后我看到了该功能:

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
    


编译时有一个错误:

Bitcast requires both operands to be pointer or neither
  %143 = bitcast %objc_object* %142 to %PSs9AnyObject_, !dbg !511
Bitcast requires both operands to be pointer or neither
  %144 = bitcast %PSs9AnyObject_ %143 to i8*, !dbg !511
Bitcast requires both operands to be pointer or neither
  %221 = bitcast %objc_object* %220 to %PSs9AnyObject_, !dbg !517
Bitcast requires both operands to be pointer or neither
  %222 = bitcast %PSs9AnyObject_ %221 to i8*, !dbg !517
Bitcast requires both operands to be pointer or neither
  %297 = bitcast %objc_object* %296 to %PSs9AnyObject_, !dbg !522
Stored value type does not match pointer operand type!
  store %PSs9AnyObject_ %297, %objc_object** %298, align 8, !dbg !522
 %objc_object*Stored value type does not match pointer operand type!
  store %PSs9AnyObject_ %297, %objc_object** %303, align 8, !dbg !526
 %objc_object*Stored value type does not match pointer operand type!
  store %PSs9AnyObject_ %297, %objc_object** %319, align 8, !dbg !530
 %objc_object*Stored value type does not match pointer operand type!
  store %PSs9AnyObject_ %297, %objc_object** %349, align 8, !dbg !539
 %objc_object*Bitcast requires both operands to be pointer or neither
  %380 = bitcast %objc_object* %379 to %PSs9AnyObject_, !dbg !542
Bitcast requires both operands to be pointer or neither
  %381 = bitcast %PSs9AnyObject_ %380 to i8*, !dbg !542
LLVM ERROR: Broken function found, compilation aborted!
Command /Applications/Xcode6-Beta3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 1

【问题讨论】:

我认为这是 Swift 编译器中的一个错误。我遇到了同样的问题。希望苹果尽快修复它。一个临时的解决方法是在 Objective-C 中编写地址簿代码(并有一个返回数据结构的方法),然后您的 Swift 代码将调用该代码。 和函数 shouldContinueAfterSelectingPerson?现在在 ios 8 上使用它的正确方法是什么? 我在这里回答了这个问题:***.com/questions/24678374/… 谢谢,您的解决方案对我有用!!!! 【参考方案1】:

你有我没有的一半答案。 在手机中使用您的代码之前,您需要进行检查:

            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)
                    

                                    
            

【讨论】:

以上是关于ABPeoplePickerNavigationController shouldContinueAfterSelectingPerson 已弃用 Swift的主要内容,如果未能解决你的问题,请参考以下文章