【问题标题】:contact access permission is shown in simulator but not on real device sometimes swift联系人访问权限显示在模拟器中,但在真实设备上有时不显示
【发布时间】:2018-10-19 21:06:33
【问题描述】:

我有一个请求访问联系人的简单代码

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)
            }
          }
        }
}

此代码在模拟器上运行良好。当我在模拟器上删除应用程序并清理然后再次构建和运行应用程序时,它工作正常,会出现一个带有权限请求的弹出视图,但是在真实设备上,当我从手机中删除应用程序并清理时,权限会在第一次弹出时弹出构建并运行我没有再次收到弹出权限请求

【问题讨论】:

    标签: ios swift cncontactstore


    【解决方案1】:

    当您删除一个应用程序时,如果您想在同一日期删除它,iOS 会保留一天的捆绑标识符权限,您有三个选项

    1. 通过将 iPhone OS (iOS) 日期增加一天来更改 iPhone OS (iOS) 数据
    2. 等一天
    3. 重置设备设置

    Click here苹果文档参考,我截取了屏幕截图,您也可以查看。

    【讨论】:

    • 嗨,Madgy,我试过了,问题是如果我授予访问权限,然后我从手机中删除应用程序并在设备上重新安装所有应用程序仍然记得我授予了访问权限。
    • 嗨@Ahmed 很抱歉错过了理解你的问题我更新了你可以检查的答案,再次抱歉:(
    • 感谢您的问题,但如何重新构建您的问题以使其对其他人更有用
    猜你喜欢
    • 2010-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多