2016-10-24 2 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 충돌이있다. 스택을 와인딩 및 po $arg1을 실행하는

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

이 나는 ​​또한 '링크 프레임 워크에서 Contacts.frameworkContactsUI.framework을 포함했다 dict

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

루트에 Info.plist에 필요한 라인을 가지고 ... 다음을 던졌습니다 및 도서관 '대상 속성 (일반)

+1

기기에서 iOS 10을 실행하고 있습니까? 프로젝트를 청소하거나 장치에서 응용 프로그램을 삭제하거나 때때로 다시 시작하는 데 도움이됩니다 –

+1

이 링크를 확인하십시오 http://stackoverflow.com/questions/14704310/error-couldnt-materialize-struct-couldnt-read-eax –

+0

@josip 제거를 시도했습니다. 전화, 재시작, Xcode 다시 시작 및 프로젝트 청소 (행운) : ( – Brendan

답변

3

연락처 설명에 대한 plist 항목을 추가하고 코드를 내 swi에서 사용하기 위해 약간 수정했습니다. 내가 그것을 알아 냈어 그래서 피트 3.0 프로젝트, 다음 코드는 내 아이폰 OS

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

확인 10.0.2에 매력처럼 작동한다 - 내가 두려워 분명 아무것도하지 않았다.

XCode가 내 Info.plist을 복제했으며 내 루트 디렉토리에 Info.plist이 아닌 복사본을 구문 분석하고로드했습니다. 하나의 파일에 NSContactsUsageDescription을 추가했지만 다른 파일을 읽었으므로 충돌이 발생했습니다.

관련 문제