【问题标题】:IOS App is closing at allowing to access to Adress BookIOS App 正在关闭允许访问地址簿
【发布时间】:2021-10-02 10:51:41
【问题描述】:

我的应用程序包含访问地址簿的请求。当我按下警报中的“允许”按钮时,应用程序正在关闭。哪里可能出错?有代码:

func getContactFromCNContact() -> [CNContact] {
        let contactStore = CNContactStore()
        let keysToFetch = [
            CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
            CNContactGivenNameKey,
            CNContactMiddleNameKey,
            CNContactFamilyNameKey,
            CNContactEmailAddressesKey,
            CNContactPhoneNumbersKey,
            CNContactImageDataKey,
        ] as [Any]
        
        var allContainers: [CNContainer] = []
        do {
            allContainers = try contactStore.containers(matching: nil) 
        
        var results: [CNContact] = []
        
        for container in allContainers {
            
            let fetchPredicate = CNContact.predicateForContactsInContainer(withIdentifier: container.identifier)
            do {
                let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
                results.append(contentsOf: containerResults)
            } catch {
                print("Error fetching results for container")
            }
        }
        return results
    }

【问题讨论】:

  • 发布您的控制台显示的错误..
  • 问题是没有错误,更新到AppStore后出现,模拟器和我自己的手机测试我的应用程序没有任何问题

标签: ios permissions


【解决方案1】:

确保您的Info.plist 中有密钥NSContactsUsageDescription 的使用说明且不为空。

【讨论】:

  • 喜欢吗?隐私 - 联系人使用说明 - 允许联系人访问
  • @elmira 看起来不错。如果不是这种情况,并且崩溃仅发生在 appstore 版本上,您可以在 Xcode - 窗口 - 管理器 - 选择您的应用程序 - 崩溃中查看崩溃报告。您需要一个可以访问您应用的 developer.apple.com 的帐户才能登录 xcode。
  • 这个参数对吗?应用程序使用非豁免加密编号。如果我在我的应用程序中使用地址簿
  • @elmira 您可以在应用程序的其他部分使用它(很可能您不需要),但对于地址簿则不需要。
  • 感谢您的回答!问题解决了:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 2012-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多