[英]contact access permission is shown in simulator but not on real device sometimes swift
I have a simple code that request access to contacts我有一个请求访问联系人的简单代码
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)
}
}
}
}
This code works fine on simulator.此代码在模拟器上运行良好。 When I delete app on the simulator and clean then build and run the app again it works fine a popup view appears with permissions request, however on real device it works the permissions pops the first time when I delete the app from the phone and clean then build and run I dont receive the pop permission request again
当我在模拟器上删除应用程序并清理然后再次构建并运行该应用程序时,它可以正常工作,会出现一个带有权限请求的弹出视图,但是在真实设备上它可以正常工作,当我从手机中删除应用程序并清理时,权限会在第一次弹出构建并运行我没有再次收到弹出权限请求
When you delete an app the iOS keeps the permissions for a day for bundle identifier if you want to remove it in the same date you have a three options当您删除应用程序时,如果您想在同一天删除它,iOS 会将捆绑标识符的权限保留一天,您有三个选项
Click here the apple docs reference that i take the screenshot form it also you can check it. 单击此处我截取屏幕截图的苹果文档参考,您也可以查看它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.