0

今天发现了一个问题。

我正在使用 DigitsKit + Parse、用于用户真实验证的 DigitsKit 和 Parse 作为有用的框架,以便为用户和我提供轻松的 sinUp、登录等。

下面是它的工作原理:

  1. 用户在 textField 中输入他们的电话号码和密码

  2. 在 DigitsKit 使用 SMS 和短代码验证之后,该用户是真实的,短信来到 USER 并且他/她在验证文本字段中输入它。如果一切正常 -> 用户名和密码以 PFUser 身份存储在 Parse DB 中。

    用户名(在 ParseDB 中)= 用户的移动电话(在 textField 中)

  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( {$0.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 中的用户名进行比较,有什么建议我应该怎么做?或任何命中/解决方案?

PS,我在数组、字典和其他数组/键值类型的数据和循环方面也遇到了麻烦,所以任何帮助都是完美的

4

1 回答 1

0

解决了使用 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 { $0.value.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet).reduce("", combine: {$0+$1})}
//                            NSLog("%@", numbers.map( {$0.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
             }
        })


    }
于 2015-08-04T20:39:20.890 回答