今天遇到了问题。
我正在使用DigitsKit + Parse,DigitsKit进行用户真实验证和Parse作为有用的框架,以便为用户和我提供简单的sinUp,登录等。
以下是它的工作原理:
用户在textField
之后,DigitsKit通过短信和短代码验证该用户 是真的,短信来到USER,他/她在验证中键入它 文本域。如果一切正常 - >用户名和密码存储在 将DB解析为PFUser。
用户名(在ParseDB中)=用户' sMobilePhone(在 textField)
比签名和登录后用户按下按钮' 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.
}
}
我不能将每个phoneNumber与ParseDB中用户的名字进行比较,任何建议我该怎么做?或任何点击/解决方案?
P.S,我对数组,字典和其他数组/键值类型的数据和循环也有一些麻烦,所以任何帮助都将是完美的
答案 0 :(得分: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
}
})
}