2016-10-24 14 views
1

連絡先フレームワークにアクセスしようとしているため、新しい連絡先をユーザーのアドレス帳に保存できます。私はマークされた行でiOS 10の連絡先フレームワークにアクセスしようとするとクラッシュする

func requestForAccess(completion: (granted: Bool) ->()) { 

    dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_BACKGROUND.rawValue), 0), { 
     let authStatus = CNContactStore.authorizationStatusForEntityType(.Contacts) 

     switch authStatus { 
     case .Authorized: 
      completion(granted: true) 
     case .Denied, .NotDetermined: 

      // CRASH HERE before the completion block is called, after calling 
      // requestAccessForEntityType 

      self.contactStore.requestAccessForEntityType(.Contacts, completionHandler: { (access, accessError) ->() in 
       if access { 
        completion(granted: access) 
       } else { 
        if authStatus == .Denied { 
         dispatch_async(dispatch_get_main_queue(), {() ->() in 
          let msg = "\(accessError!.localizedDescription)\n\nPlease allow the app to access your contacts through the Settings." 
          //self.alertService.showAlert(msg) 
         }) 
        } 
       } 
      }) 
     default: 
      completion(granted: false) 
     } 
    }) 
} 

...ファイルの先頭に次のコード...

import Contacts 
import ContactsUI 

を持っているし、方法を含む、SIABRTクラッシュがあります。私はルートにdict

<key>NSContactsUsageDescription</key> 
<string>We need to access Contacts to import entries direct from the app.</string> 

Info.plistに必要なラインを持っている...

error: Couldn't materialize: couldn't read the value of register x0 
Errored out in Execute, couldn't PrepareToExecuteJITExpression 

をスタックを下巻きしてpo $arg1は以下をスローランニング、私もリンクされたフレームワーク「でContacts.frameworkContactsUI.frameworkが含まれています(一般)

+1

お使いの端末はiOS 10を実行していますか?プロジェクトをクリーニングしたり、デバイスからアプリケーションを削除したり、時々再起動したりするのに役立ちます –

+1

このリンクをチェックしてくださいhttp://stackoverflow.com/questions/14704310/error-couldnt-materialize-struct-couldntread-eax –

+0

@josipアンインストールを試みました( – Brendan

答えて

3

連絡先の説明のためのplistエントリを追加しました。あなたのコードを私のswiで使用するために少し変更しました。フィート3.0プロジェクト、コードに続く10.0.2

override func viewDidAppear(_ animated: Bool) { 
     super.viewDidAppear(animated); 
     self.requestForAccess { (gotAccess) in 
      print(gotAccess) 
     } 
    } 

    func requestForAccess(_ completion: @escaping (_ granted: Bool) ->()) { 
     DispatchQueue.global(qos: DispatchQoS.QoSClass.background).async { 
      let authStatus = CNContactStore.authorizationStatus(for: .contacts) 

      switch authStatus { 
      case .authorized: 
       completion(true) 
      case .denied, .notDetermined: 

       self.contactStore.requestAccess(for: .contacts, completionHandler: { (access, accessError) ->() in 
        if access { 
         completion(access) 
        } else { 
         if authStatus == .denied { 
          DispatchQueue.main.async { 
           let msg = "\(accessError!.localizedDescription)\n\nPlease allow the app to access your contacts through the Settings." 
           print(msg) 
          } 
         } 
        } 
       }) 
      default: 
       completion(false) 
      } 
     } 
    } 
3

[OK]を、私のiOSの上で魔法のように取り組んでいるので、私はそれを考え出した - それは私が怖い明らかに何もありませんでした。

何らかの理由でXCodeがInfo.plistを複製し、ルートディレクトリにInfo.plistではなくコピーを解析してロードしていました。私はNSContactsUsageDescriptionを1つのファイルに追加しましたが、それはもう1つのファイルを読み込んでいたため、クラッシュしました。

関連する問題