gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:10:57 25 4
gpt4 key购买 nike

今天遇到一个问题。

我使用 DigitsKit + Parse、DigitsKit for User real-Validation 和 Parse 作为有用的框架,让用户和我都可以轻松进行 sinUp、登录等操作。

它的工作原理如下:

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

  2. DigitsKit 使用短信和短代码进行验证后,该用户是真的,短信发送给用户并且他/她在验证中输入它文本域。如果一切正常 -> 用户名和密码存储在将 DB 解析为 PFUser。

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

  3. 注册并登录后,用户在新 View 上按下“FindFriends”按钮,这里应该是 friend 搜索系统,但我在这里遇到了问题...请查看下面的 Controller 案例:

    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 中的用户名进行比较,有什么建议我应该如何做到这一点?或者有任何点击/解决方案吗?

P.S,我对数组、字典和其他数组/键值类型的数据和循环也有一些麻烦,所以任何帮助都是完美的

最佳答案

解决了使用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
}
})


}

关于ios - 从 AddressBook 中获取人数并将其与 Parse DB 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31772908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com