联系人访问权限在模拟器中显示,但有时在真实设备上不显示 swift
contact access permission is shown in simulator but not on real device sometimes swift
我有一个请求访问联系人的简单代码
override func viewDidLoad() {
super.viewDidLoad()
fetchContacts()
}
func fetchContacts()
{
let allowedCharset = CharacterSet
.decimalDigits
let store = CNContactStore()
store.requestAccess(for: .contacts) { (granted, err) in
if let error = err
{
print("failed to access",error)
return
}
if (granted)
{
///// after we get access to fetch contacts //// we reload table view data ///
print("access granted")
let keys = [CNContactGivenNameKey,CNContactPhoneNumbersKey,CNContactFamilyNameKey,CNContactMiddleNameKey]
let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
do {
try store.enumerateContacts(with: request, usingBlock: { (contact, stopPointerIfYouWantToStopEnumerating) in
let array = contact.phoneNumbers
for number in array
{
let fullName = contact.givenName + contact.middleName
let lastName = contact.familyName
let value = number.value.stringValue
let number = String(value.unicodeScalars.filter(allowedCharset.contains))
print (number)
/////////// 4 cases we just need the phone not to be zero ///////
if (fullName != "SPAM")
{
self.firstName.append(fullName)
self.lastName.append(lastName)
self.numberArray.append(number)
}
}
})
//self.table()
}
catch let err2 {
print ("failer to enurmerate",err2)
}
}
}
}
此代码在模拟器上运行良好。当我在模拟器上删除应用程序并清理然后构建并再次 运行 应用程序时它工作正常弹出视图出现权限请求,但是在真实设备上它工作当我从中删除应用程序时第一次弹出权限phone 然后清理然后构建 运行 我没有再次收到 pop 权限请求
当您删除应用程序时,iOS 会保留捆绑包标识符一天的权限,如果您想在同一天删除它,您有三个选择
- 通过增加 iPhone OS (iOS) 日期来更改 iPhone OS (iOS) 数据
- 等一天
- 重置设备设置
Click here apple docs 参考,我截屏了,你也可以查看。
我有一个请求访问联系人的简单代码
override func viewDidLoad() {
super.viewDidLoad()
fetchContacts()
}
func fetchContacts()
{
let allowedCharset = CharacterSet
.decimalDigits
let store = CNContactStore()
store.requestAccess(for: .contacts) { (granted, err) in
if let error = err
{
print("failed to access",error)
return
}
if (granted)
{
///// after we get access to fetch contacts //// we reload table view data ///
print("access granted")
let keys = [CNContactGivenNameKey,CNContactPhoneNumbersKey,CNContactFamilyNameKey,CNContactMiddleNameKey]
let request = CNContactFetchRequest(keysToFetch: keys as [CNKeyDescriptor])
do {
try store.enumerateContacts(with: request, usingBlock: { (contact, stopPointerIfYouWantToStopEnumerating) in
let array = contact.phoneNumbers
for number in array
{
let fullName = contact.givenName + contact.middleName
let lastName = contact.familyName
let value = number.value.stringValue
let number = String(value.unicodeScalars.filter(allowedCharset.contains))
print (number)
/////////// 4 cases we just need the phone not to be zero ///////
if (fullName != "SPAM")
{
self.firstName.append(fullName)
self.lastName.append(lastName)
self.numberArray.append(number)
}
}
})
//self.table()
}
catch let err2 {
print ("failer to enurmerate",err2)
}
}
}
}
此代码在模拟器上运行良好。当我在模拟器上删除应用程序并清理然后构建并再次 运行 应用程序时它工作正常弹出视图出现权限请求,但是在真实设备上它工作当我从中删除应用程序时第一次弹出权限phone 然后清理然后构建 运行 我没有再次收到 pop 权限请求
当您删除应用程序时,iOS 会保留捆绑包标识符一天的权限,如果您想在同一天删除它,您有三个选择
- 通过增加 iPhone OS (iOS) 日期来更改 iPhone OS (iOS) 数据
- 等一天
- 重置设备设置
Click here apple docs 参考,我截屏了,你也可以查看。