0
我試圖在iOS 9在迅速獲得3接觸不靈
func getInnerContacts()-> Observable<[CNContact]>{
return Observable<[CNContact]>.create({ (observer) -> Disposable in
var contacts = [CNContact]()
let keysToFetch = [CNContactFormatter.descriptorForRequiredKeys(for: .fullName), CNContactPhoneNumbersKey] as [Any]
self.contactStore.requestAccess(for: .contacts, completionHandler: { (granted, error) -> Void in
if granted {
let predicate = CNContact.predicateForContactsInContainer(withIdentifier: self.contactStore.defaultContainerIdentifier())
do {
contacts = try self.contactStore.unifiedContacts(matching: predicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
contacts = newContacts.filter({ (contact) -> Bool in
return !contact.phoneNumbers.isEmpty && contact.givenName != "" || !contact.phoneNumbers.isEmpty && contact.familyName != ""
})
observer.onNext(contacts)
observer.onCompleted()
}catch {
observer.onError(error)
}
}
})
return Disposables.create()
})
}
接觸(SWIFT 3),但它不能正常工作,而且,我看不到的權限警惕。 執行我先檢查了iOS版本,如在此之前:
if #available(iOS 10 , *){
}else if #available(iOS 9, *){
}
然後我加入許可標記,Privacy - Contacts Usage Description
到Info.plist文件。這適用於IOS 10細,任何想法我怎麼能在IOS實現這個9
它在其他情況下工作,但不在我的工作。在iOS 9或更高版本上運行的應用程序的首次啓動期間沒有許可警報,但它適用於iOS 10 –