ユーザーの連絡先のいずれかがすでに私のプラットフォームに参加しているかどうかを確認する友達検索ページを開発しようとしています。それほど長くはかからないはずですが、2〜3分くらいかかるので、どこかおかしいと思います。私はそれが何であるかについていくつかのアイデアを持っています:
このアプリケーションは、バックグラウンドスレッドから自動レイアウトエンジンを変更しているため、エンジンの破損や奇妙なクラッシュが発生する可能性があります。これにより、将来のリリースで例外が発生します。
エラーが何度も発生するため、forループの1つで問題が発生していると思います。
制約を解除して回復を試みますNSLayoutConstraint:0x127c2ab00 UITextView:0x127011000 '名前の姓が作成されました...'。centerY == UIView:0x1278c21b0.centerY>
let store = CNContactStore()
//Find all the contacts and store them in an instance variable
store.requestAccessForEntityType(.Contacts) { granted, error in
guard granted else {
dispatch_async(dispatch_get_main_queue()) {
// user didn't grant authorization, so tell them to fix that in settings
print(error)
}
return
}
// get the contacts
self.showActivityIndicator()
var localcontacts = [CNContact]()
let request = CNContactFetchRequest(keysToFetch: [CNContactIdentifierKey, CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName), CNContactPhoneNumbersKey])
request.sortOrder = CNContactSortOrder.GivenName
do {
try store.enumerateContactsWithFetchRequest(request) { contact, stop in
if !contact.phoneNumbers.isEmpty {
localcontacts.append(contact)
}
}
} catch {
print(error)
}
self.cncontacts = localcontacts
var cs = [contactObject]()
for contact in self.cncontacts {
let formatter = CNContactFormatter()
formatter.style = .FullName
let name = formatter.stringFromContact(contact)
var numbers = [String]()
if (contact.isKeyAvailable(CNContactPhoneNumbersKey)) {
for phoneNumber:CNLabeledValue in contact.phoneNumbers {
let a = phoneNumber.value as! CNPhoneNumber
let number = a.stringValue.stringByReplacingOccurrencesOfString(" ", withString: "-", options: NSStringCompareOptions.LiteralSearch, range: nil)
numbers.append(number)
}
}
if numbers.count > 0 {
let c : contactObject = contactObject.init()
c.name = name!
c.numbers = numbers
cs.append(c)
}
}
self.contacts = cs
//For each contactObject check if there's an user associated with it
for localcontact in self.contacts {
print(localcontact.name)
for number in localcontact.numbers {
print(number)
if number.hasPrefix("+1") || number.hasPrefix("(") || number.hasPrefix("1"){
//Is american phone number
var formattednumber = number
if number.hasPrefix("+1") {
if number.hasPrefix("+1 "){
formattednumber = number.stringByReplacingOccurrencesOfString("+1 ", withString: "")
formattednumber = formattednumber.stringByReplacingOccurrencesOfString(" ", withString: "")
}
else if number.hasPrefix("+1-"){
formattednumber = number.stringByReplacingOccurrencesOfString("+1-", withString: "")
}
else {
formattednumber = number.stringByReplacingOccurrencesOfString("+1", withString: "")
}
}
else if number.hasPrefix("1"){
if number.hasPrefix("1-") {
formattednumber = number.stringByReplacingOccurrencesOfString("1-", withString: "")
}
else{
formattednumber = number.stringByReplacingOccurrencesOfString("1 ", withString: "")
}
}
formattednumber = formattednumber.stringByReplacingOccurrencesOfString(" ", withString: "-")
print(formattednumber)
let userquery = PFUser.query()
userquery?.whereKey("phone", equalTo: formattednumber)
userquery?.getFirstObjectInBackgroundWithBlock({ (user, error) in
if error == nil {
if let user = user as? PFUser {
localcontact.userid = user.objectId!
}
}
})
}
}
}
self.hideActivityIndicator()
let encodedData = NSKeyedArchiver.archivedDataWithRootObject(self.contacts)
userDefaults.setObject(encodedData, forKey: "contacts")
userDefaults.synchronize()
self.tableView.reloadData()
}
私が間違っている可能性があることについて何か提案や考えがあれば、私に知らせていただければ幸いです。前もって感謝します。
私の推測は
self.showActivityIndicator()
self.hideActivityIndicator()
self.tableView.reloadData()
すべてUIのレイアウトを変更しようとしているため、警告が表示されます。
でそれらをやってみてください
dispatch_async(dispatch_get_main_queue()){}
ブロック
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加