代码之家  ›  专栏  ›  技术社区  ›  Ahmed

联系人访问权限在模拟器中显示,但在实际设备上不显示

  •  0
  • Ahmed  · 技术社区  · 7 年前

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

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

    这段代码在模拟器上运行良好。当我在模拟器上删除应用程序,然后清理,然后构建并再次运行该应用程序时,它工作正常,弹出窗口显示权限请求,但是在真实设备上,它工作权限弹出窗口,当我从手机上删除应用程序,然后清理,然后构建并再次运行时,我不会再收到弹出窗口权限请求

    1 回复  |  直到 6 年前
        1
  •  2
  •   Magdy Zamel    7 年前

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

    enter image description here

    Click here 苹果文件参考,我采取的截图形式它也可以检查它。