下面是代码
func get_all_user_contacts(){ let status = CNContactStore.authorizationStatus(for: .contacts) if status == .denIEd || status == .restricted { presentSettingsActionSheet() return } // open it let store = CNContactStore() store.requestAccess(for: .contacts) { granted,error in guard granted else { dispatchQueue.main.async { self.presentSettingsActionSheet() } return } // get the contacts var contacts = [CNContact]() let request = CNContactFetchRequest(keysToFetch: [CNContactIDentifIErKey as Nsstring,CNContactFormatter.descriptorForrequiredKeys(for: .fullname)]) do { try store.enumerateContacts(with: request) { contact,stop in contacts.append(contact) } } catch { print(error) } // do something with the contacts array (e.g. print the names) let formatter = CNContactFormatter() formatter.style = .fullname for contact in contacts { let MobNumVar = ((contact.phoneNumbers.first?.value)! as CNPhoneNumber).stringValue print(MobNumVar) print(formatter.string(from: contact) ?? "???") } }}
当我运行这个应用程序它崩溃,我不知道我哪里出错了.
任何人都可以帮助我..我将不胜感激.
• CNContactIDentifIErKey• CNContactFormatter.descriptorForrequiredKeys(for: .fullname)
…但是你正试图访问contact.phoneNumber.
您只能访问keysToFetch中指定的密钥,因此您需要将CNContactPhoneNumbersKey添加到该数组
总结以上是内存溢出为你收集整理的ios – CNPropertyNotFetchedException应用程序崩溃全部内容,希望文章能够帮你解决ios – CNPropertyNotFetchedException应用程序崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)