Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在swift中,更新应用程序在不显示联系人权限的情况下终止_Ios_Swift - Fatal编程技术网

Ios 在swift中,更新应用程序在不显示联系人权限的情况下终止

Ios 在swift中,更新应用程序在不显示联系人权限的情况下终止,ios,swift,Ios,Swift,我已使用联系人权限阅读swift 5中电话簿中的联系人。我已经更新到苹果商店。但当它在IOS设备中更新时,它没有显示联系人权限,而是终止了它的应用程序。但如果我卸载应用程序,然后从play store重新安装,它会显示联系人权限。它工作正常。但用户更新应用程序不会显示 当用户导航到view controller时,联系人权限和应用程序终止 Heere是我的信息列表 检查viewController的viewDidLoad中的访问权限 if (CNContactStore.authorizatio

我已使用联系人权限阅读swift 5中电话簿中的联系人。我已经更新到苹果商店。但当它在IOS设备中更新时,它没有显示联系人权限,而是终止了它的应用程序。但如果我卸载应用程序,然后从play store重新安装,它会显示联系人权限。它工作正常。但用户更新应用程序不会显示 当用户导航到view controller时,联系人权限和应用程序终止

Heere是我的信息列表

检查viewController的viewDidLoad中的访问权限

if (CNContactStore.authorizationStatus(for: .contacts) ==  .authorized ){

    do{
        try  fetch_contacts()
    }catch let error {
        print("error-->",error)
    }
} else {

CNContactStore().requestAccess(for: .contacts, completionHandler: { granted, error in
   if (granted){
            //access allowed

        else{
            //access denied

            // Create Alert
            let alert = UIAlertController(title: "Contact", message: "Please Allow Contacts Access for this app", preferredStyle: .alert)

            // Add "OK" Button to alert, pressing it will bring you to the settings app
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
                UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
            }))
            // Show the alert with animation
            self.present(alert, animated: true)
        }
    })
}
这是我从电话簿中获取数据的方法

func fetch_contacts(){
  let contactStore = CNContactStore()
   var contacts = [CNContact]()
   let keys = [
    CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
    CNContactPhoneNumbersKey,
    CNContactEmailAddressesKey
    ] as [Any]
  let request = CNContactFetchRequest(keysToFetch: keys as! [CNKeyDescriptor])
   do {
      try contactStore.enumerateContacts(with: request){
        (contact, stop) in
        // Array containing all unified contacts from everywhere
        contacts.append(contact)
        for phoneNumber in contact.phoneNumbers {
            if let number = phoneNumber.value as? CNPhoneNumber, let label = phoneNumber.label {
                let localizedLabel = CNLabeledValue<CNPhoneNumber>.localizedString(forLabel: label)

                var name = contact.givenName;


                let charsToRemove: Set<Character> = Set("()+-".characters)
                let newNumberCharacters = String(number.stringValue.characters.filter { !charsToRemove.contains($0) })
                // print("newNumberCharacters--",newNumberCharacters)

                var number = newNumberCharacters.replacingOccurrences(of: " ", with: "")
                //  a.suffix(4)
                //print(number.suffix(11))
                let last11 = String(number.characters.suffix(11))

                self.arrRes += [
                    ["name":name as Any,"number":last11 as Any]
                ]

                // self.arrRes.append(a);
                /*
                 statusList = [
                 ["desc":"--Select--" as AnyObject,"type":"--Select--" as AnyObject]
                 ]
                 **/
            }
        }
    }
    // print(contacts)
    //print("arrRes******>",arrRes)
    if(self.arrRes.count>0){
        self.tableView.reloadData()
    }

} catch {
    print("unable to fetch contacts")
}
}
我已经两次更新了应用程序。它解决不了问题。当我转到viewController时,应用程序被终止


请帮助我代码有什么问题

当您从应用商店安装旧版本的应用程序,然后从Xcode或TestFlight运行升级版本时会发生什么?它撞在哪条线上?什么是异常消息?@Paulw11你好,先生,我没有那样测试。我是checking@Paulw11先生,在我的设备中运行良好。但当现有的应用程序安装在用户设备上时并没有破坏。但我找不到终止的原因。但若用户卸载应用程序,然后再次安装,它工作正常。你们需要确定它崩溃的原因和地点。这可能与联系人权限无关。您是否已在App Store Connect或Xcode中查看崩溃日志?