2016-05-05 4 views
0

ユーザーの連絡先が既に自分のプラットフォームに参加しているかどうかを確認するfind friendsページを開発しようとしています。それはあまりにも長くかかるべきではありませんが、2〜3分ほどかかるので、何か問題があると思います。私はそれが何であるかについてのいくつかのアイデアを持っています:ユーザーNSContactsの友だちページを見つけるのが非常に遅い+ "このアプリケーションは、自動スレッドエンジンから自動レイアウトエンジンを変更しています"

  • 私は非同期呼び出しのどこかでうんざりしています。これは私の主な仮説ですが、私はどこにいるのか分かりません。

このアプリケーションは、エンジンの破損や奇妙なクラッシュにつながることができ、バックグラウンドスレッドから自動レイアウトエンジンを変更されます。コンソール上で、私は次のエラーを取得するので、それにもかかわらず、原因である可能性が非常に高いです。この は、将来のリリースで例外を発生させます。

私はエラーが複数回発生するので、forループの1つの内側に邪魔になると思います。

が制約NSLayoutConstraintを壊すことで回復を試みます:0x127c2ab00 UITextView:

  • 私の他のアイデアは、遅延は私も取得するため、制約とは何かを持っているということです0x127011000'Nameが作成LASTNAME .. 。。 "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() 
    
    
          } 
    

    あなたは私はあなたが私に教えてできれば、私はそれを本当に感謝間違っていることができるかについての提案や考えを持っている場合

    。前もって感謝します。

答えて

1

私の推測では、すべてのUIのレイアウトを変更しようとしている

self.showActivityIndi​​cator()

self.hideActivityIndi​​cator()

self.tableView.reloadData()

ですそれゆえに警告。

dispatch_asyncでそれらをやってみ(dispatch_get_main_queue()){ }

ブロック

+0

私は同意し、私もそう思って、私は(hideAcitivityIndi​​catorをコメントしようとした)とshowActivityIndi​​cator()何もかわった。私はtableview.reloaddata()を削除しようとしませんでしたが、データがすべて配列にロードされたら、データを再ロードする方法がわかりません。どのように私が別の方法でそれを行うことができるかについての提案はありますか? –

+1

self.tableView.reloadData()の代わりにdispatch_async(dispatch_get_main_queue()){self.tableView.reloadData()}を試しましたか? –

+0

これは非同期呼び出しの内側か外にあるべきですか? –

関連する問題