gpt4 book ai didi

ios - swift 3 : CNcontactpicker's phonenumber return 'not fetched' in device

转载 作者:行者123 更新时间:2023-11-30 12:03:31 25 4
gpt4 key购买 nike

我们的应用程序具有获取设备联系人的功能,我刚刚使用了 CNcontacpickerview,当我在模拟器上运行它时它可以工作,但是当它在设备上运行时,电话号码返回“未获取”。是因为我的允许还是什么?奇怪的是它可以在模拟器上运行

enter image description here

import UIKit
import ContactsUI
import MessageUI

class SharedAboutViewController: UIViewController,UITableViewDelegate,UITableViewDataSource,CNContactPickerDelegate,MFMessageComposeViewControllerDelegate {

@IBOutlet weak var tableview: UITableView!

override func viewDidLoad() {
super.viewDidLoad()
self.tableview.delegate = self;
self.tableview.dataSource = self;
// Do any additional setup after loading the view.
}

func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
//... handle sms screen actions
self.dismiss(animated: true, completion: nil)
}

func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact]) {
for contact in contacts {
print(contact)
}

let when = DispatchTime.now() + 0.2 // change 2 to desired number of seconds
DispatchQueue.main.asyncAfter(deadline: when) {
// Your code with delay
if (MFMessageComposeViewController.canSendText()) {
let controller = MFMessageComposeViewController()
controller.body = "Message Body"
controller.recipients = ["hello"]
controller.messageComposeDelegate = self
self.present(controller, animated: true, completion: nil)
}
}

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let contactPicker = CNContactPickerViewController()
contactPicker.delegate = self
contactPicker.displayedPropertyKeys =
[CNContactNicknameKey
,CNContactEmailAddressesKey]

self.present(contactPicker, animated: true, completion: nil)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5;
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cells");
cell?.textLabel?.text = "hello";
return cell!;
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.view.frame.height*0.08;
}
}

最佳答案

已解决

我刚刚在我的页面中添加了此代码以显示权限弹出窗口

let addressBookStore = CNContactStore()

addressBookStore.requestAccess(for: CNEntityType.contacts) { (isGranted, error) in
print(isGranted)
print(error)
}

关于ios - swift 3 : CNcontactpicker's phonenumber return 'not fetched' in device,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46927725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com