应用程序崩溃在iphone 6

时间:2015-08-07 15:05:03

标签: ios swift

enter image description here enter image description here在我的应用中,我需要用户的联系人列表。我的应用程序适用于iphone 4s,5,5s,但它在iphone 6崩溃。我不知道是什么问题。请帮我。这是我用来获取联系人列表的方法。

    let authorizationStatus = ABAddressBookGetAuthorizationStatus()

    let addressBookRef: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()

    switch authorizationStatus {
    case .Denied, .Restricted:

        println("Denied")

    case .Authorized:

        println("Authorized")

        let allContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef).takeRetainedValue() as Array
        for record in allContacts {
            let currentContact: ABRecordRef = record
            let currentContactName = ABRecordCopyCompositeName(currentContact).takeRetainedValue() as String
            let unmanagedPhones = ABRecordCopyValue(currentContact, kABPersonPhoneProperty)
            let phones: ABMultiValueRef = Unmanaged.fromOpaque(unmanagedPhones.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef

            let countOfPhones = ABMultiValueGetCount(phones)

            for index in 0..<countOfPhones{
                let unmanagedPhone = ABMultiValueCopyValueAtIndex(phones, index)
                let phone: String = Unmanaged.fromOpaque(unmanagedPhone.toOpaque()).takeUnretainedValue() as NSObject as! String
                var params : Dictionary = ["name" : currentContactName, "number" : phone]

                self.phonesArray.addObject(params)

            }

        }

    case .NotDetermined:

        println("Not Determined")

        var err: Unmanaged<CFError>? = nil

        ABAddressBookRequestAccessWithCompletion(addressBookRef) {
            (granted: Bool, error: CFError!) in
            dispatch_async(dispatch_get_main_queue()) {
                if !granted {
                    println("Just denied")
                } else {
                    println("Just authorized")
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试将“as String”替换为“as CFString”