从 AddressBook 中获取人数并将其与 Parse DB 进行比较

Take number of person from AddressBook and compare it to Parse DB

今天遇到了问题。

我正在使用 DigitsKit + Parse、用于用户真实验证的 DigitsKit 和 Parse 作为有用的框架来为用户和我简化 sinUp、登录等。

工作原理如下:

  1. 用户在文本字段中输入电话号码和密码

  2. 在 DigitsKit 使用短信和短代码验证之后,该用户 是真实的,短信到达 USER 并在验证中输入 he/she 文本域。如果一切正常 -> 用户名和密码存储在 将 DB 解析为 PFUser。

    用户名(在 ParseDB 中)= 用户的手机(在 文本字段)

  3. 注册并登录后,用户在新视图上按下按钮 'FindFriends',这里应该是朋友搜索系统,但我这里有问题...看情况对于下面的控制器,请:

    import UIKit
    import SwiftAddressBook
    import AddressBook
    import Parse
    
    class FriendsViewController: UIViewController {
    let status : ABAuthorizationStatus = SwiftAddressBook.authorizationStatus()
    
        var addrssbk : ABAddressBook!
    var addressBook: SwiftAddressBook? = swiftAddressBook
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        GetContactNumbers()
              }
    
    
    
    override func viewDidAppear(animated: Bool) {
    
    
    }
    
    
    
    
    
    
    func createAddressBook() -> Bool {
    if self.addressBook != nil {
        return true
    }
    var err : Unmanaged<CFError>? = nil
    let addrssbk : ABAddressBook? = ABAddressBookCreateWithOptions(nil, &err).takeRetainedValue()
    if addrssbk == nil {
        println(err)
        self.addressBook = nil
        return false
    }
    self.addrssbk = addrssbk
    return true
    }
    
       func determineStatus() -> Bool {
    let status = ABAddressBookGetAuthorizationStatus()
    switch status {
    case .Authorized:
        return self.createAddressBook()
    case .NotDetermined:
        var ok = false
        ABAddressBookRequestAccessWithCompletion(nil) {
            (granted:Bool, err:CFError!) in
            dispatch_async(dispatch_get_main_queue()) {
                if granted {
                    ok = self.createAddressBook()
                }
            }
        }
        if ok == true {
            return true
        }
        self.addressBook = nil
        return false
    case .Restricted:
        self.addressBook = nil
        return false
    case .Denied:
        self.addressBook = nil
        return false
    }
    }
    
    
    func GetContactNumbers() {
    
    swiftAddressBook?.requestAccessWithCompletion({ (success, error) -> Void in
        if success {
            if let people = swiftAddressBook?.allPeople {
                for person in people {
                    if let numbers = person.phoneNumbers {
                            let names = person.compositeName
                       NSLog("%@", numbers.map( {[=10=].value} ))
                       NSLog("%@", names!)
    
    
    
                       if let query = PFUser.query() {
    
                           query.whereKey("username", equalTo: "\(person.phoneNumbers)")
                           var friends = query.findObjects()
                           println(friends)
                        }
    
    
    
                    //the value entry of the multivalue struct contains the data
    
                    }
                }
            }
            //do something with swiftAddressBook
    
        }else {
            //no success. Optionally evaluate error
         }
    })
    
    
    }
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    
    }
    

我无法获取每个电话号码并将其与 ParseDB 中的用户名进行比较,有什么建议我应该怎么做?或者任何 hits/solutions?

P.S,我在数组、字典和其他 array/key-value 类型的数据和循环方面遇到了一些麻烦,所以任何帮助都是完美的

解决了使用 map 和 stringFormation 的问题:

   func GetContactNumbers() {

        let query = PFUser.query()

        swiftAddressBook?.requestAccessWithCompletion({ (success, error) -> Void in
            if success {
                if let people = swiftAddressBook?.allPeople {
                    for person in people {
                        if let numbers = person.phoneNumbers {
                           let names = person.compositeName
                            let formatednumbers = numbers.map { [=10=].value.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet).reduce("", combine: {[=10=]+})}
//                            NSLog("%@", numbers.map( {[=10=].value} ))
                            NSLog("%@", names!)
                            println(formatednumbers)
                            query!.whereKey("username", equalTo: "\(formatednumbers)")

                            if let friends = query!.findObjects() {
                                println(friends)

                            }





                        //the value entry of the multivalue struct contains the data

                        }
                    }
                }
                //do something with swiftAddressBook

            }else {
                //no success. Optionally evaluate error
             }
        })


    }