[英]Contacts Not Fetching On Physical Device-iOS
我目前正在嘗試使用TestFlight
測試我的iOS應用,並且在獲取聯系人時TestFlight
了一些問題。 我的應用程序應該檢索通訊錄中的所有聯系人,然后在檢查Firebase以確保該聯系人尚未被邀請到該應用程序后在表格視圖中顯示它們。 在具有10個聯系人的模擬器上,它可以正常工作,但在具有100個以上聯系人的手機上,它根本無法工作。 甚至沒有聯系人出現。 我檢查了是否也啟用了聯系人。 不知道可能是什么問題。 我已附上以下代碼:
override func viewDidLoad() {
super.viewDidLoad()
contactStore.requestAccess(for: .contacts) { (success, error) in
if success{
print("Contact Authorization Successful")
}
}
fetchContacts()
tableView.delegate = self
tableView.dataSource = self
}
func fetchContacts(){
contacts = [ContactStruct]()
let key = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey, CNContactThumbnailImageDataKey] as [CNKeyDescriptor]
let request = CNContactFetchRequest(keysToFetch: key)
try! contactStore.enumerateContacts(with: request) { (contact, stoppingPointer) in
let name = contact.givenName
let familyName = contact.familyName
let fullName = contact.givenName + contact.familyName
let number = (contact.phoneNumbers[0].value ).value(forKey: "digits") as! String
let contactImage = contact.imageData
let phone = (contact.phoneNumbers[0].value ).value(forKey: "digits") as! String
self.phoneNumbersArray.append(phone)
let contactToAppend = ContactStruct(givenName: name, familyName: familyName, fullName: fullName, phoneNumber: number, contactImage: contactImage)
self.contacts.append(contactToAppend)
self.tableView.reloadData()
}
getAllUsers()
}
func getAllUsers(){
self.sectionData = [0: self.contactsOnApp as Array<AnyObject>, 1: self.usersInSchool as Array<AnyObject>, 2: self.contacts as Array<AnyObject>]
ref.child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
let user = User(snapshot: snapshot)
let currentUserSchool = user.highSchool!
for child in user.invitesFormatted {
let checkInvites = child
if let alreadyInvited = self.contacts.index(where: {$0.phoneNumber == checkInvites}){
self.contacts.remove(at: alreadyInvited)
self.sectionData = [0: self.contactsOnApp as Array<AnyObject>, 1: self.usersInSchool as Array<AnyObject>, 2: self.contacts as Array<AnyObject>]
self.tableView.reloadData()
}
}
ref.child("schools").child(currentUserSchool).child("members").observeSingleEvent(of: .value, with: { (snap) in
for child in snap.children{
let child = child as? DataSnapshot
if let otherUsers = child?.key {
ref.child("users").child(otherUsers).observeSingleEvent(of: .value, with: { (snappy) in
let personInSchool = User(snapshot: snappy)
if personInSchool.uid != uid! && self.phoneNumbersArray.contains(personInSchool.phoneNumber) {
//If contacts does have user
self.contactsOnApp.append(personInSchool)
if let itemToRemoveIndex = self.contacts.index(where: {$0.phoneNumber == personInSchool.phoneNumber}) {
self.contacts.remove(at: itemToRemoveIndex)
}
}else if personInSchool.uid != uid! {
//If contacts doesn't have user
self.usersInSchool.append(personInSchool)
}
self.sectionData = [0: self.contactsOnApp as Array<AnyObject>, 1: self.usersInSchool as Array<AnyObject>, 2: self.contacts as Array<AnyObject>]
self.tableView.reloadData()
})
}
}
})
})
}
任何幫助將不勝感激。 謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.