cncontact

Fetch Contact Image - SwiftUI

ぃ、小莉子 提交于 2021-01-28 04:05:07
问题 I'm trying to fetch the image property of a given contact . Here's what I got: Model struct Contact: Identifiable { let contact: CNContact var id: String { contact.identifier } var image: Data? { contact.imageData } var givenName: String { contact.givenName } } static func fetch(_ completion: @escaping(Result<[Contact], Error>) -> Void) { let containerID = CNContactStore().defaultContainerIdentifier let predicate = CNContact.predicateForContactsInContainer(withIdentifier: containerID()) let

IOS 13 CNContacts No Longer Working To Retrieve All Contacts

不羁的心 提交于 2020-01-01 04:16:08
问题 I have an app that has worked perfectly well with the CNContacts framework all the way up to IOS 12. I'm currently testing it with IOS 13 beta and its completely broken. I've checked the contacts permissions and deleted the app and re-allowed the permissions. This is the code I'm using to retrieve all contacts: NSError* error; CNContactStore *store = [[CNContactStore alloc]init]; [store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers: @[store

Fetching all contacts in ios Swift?

对着背影说爱祢 提交于 2019-12-28 02:28:07
问题 I am aware of the ios swift has a Contacts Framework where I can fetch contacts, but I cannot find any method to fetch all the contacts together where I can access each of the contacts from that array. All methods for fetching contacts seems to require some sort of conditions. Is there any method where I can get all the contacts together? Thanks 回答1: Many answers to Contact Framework questions suggest iterating over various containers (accounts). However, Apple's documentation describes a

How can I determine that CNContact is is favorites? [duplicate]

主宰稳场 提交于 2019-12-24 07:24:02
问题 This question already has answers here : Find Favorite contacts from the iOS Address Book API (3 answers) Closed last year . My iOS application fetches contacts from device using code [[CNContactStore new] requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) { if (granted) { NSArray *keys = @[CNContactNamePrefixKey, CNContactGivenNameKey, CNContactMiddleNameKey, CNContactFamilyNameKey, // ... NSString *containerId = store.defaultContainerIdentifier

How to force a new CNContact into a Local CNContainer?

六眼飞鱼酱① 提交于 2019-12-21 20:35:36
问题 I'm writing an app that stores contact-info fetched through REST and JSON into a container, using CNContactStore. I would like to keep these contacts separate from any other accounts, and only stored locally on the device, but a local store doesn't exist, and I can't find any way to create/activate one? I'm able to get the default store's ID (as configured on the device, e.g. iCloud), using: let store = CNContactStore() let containerID = store.defaultContainerIdentifier() ...and I can

Saving Contact Address to Unified Contact results in (CNErrorDomain error 500)

不打扰是莪最后的温柔 提交于 2019-12-21 05:06:57
问题 There is an odd error in my application that I can't find any workarounds/fixes for. For some reason, I'm able to save an address to a contact that isn't unified with a social profile (Facebook, Twitter, etc). However, when I try to add an address for my contact that is unified with Facebook or Twitter I get a weird save error: The operation couldn’t be completed. (CNErrorDomain error 500.) Here is some of the code that I'm using: if mutableContact.isKeyAvailable(CNContactPostalAddressesKey)

create new group with contacts framework, CNErrorDomain Code = 2

别来无恙 提交于 2019-12-21 04:29:28
问题 i try to create and save a group with the Contacts Framework. First the user authorize the App for contacts access. A viewcontroller is presented and with a + button user shows an alertview with textfield. The user types the group name he wants and click to button of the alertview (save). This is the code for saving the new group. The group name is available but it is not possible to save this group anyway: CNContactStore *contactStore = [CNContactStore new]; [contactStore

How to check contact source in CNContact swift?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 05:53:46
问题 In Contact apps there's group like "iCloud", "yahoo", "gmail". In swift, is it possible to fetch contact from gmail source only? 回答1: Tested code. Hope it will solve your problem... func getAppropriateName(for container: CNContainer?) -> String? { var name = "" if (container?.name == "Card") || container?.name == nil { name = "iCloud" } else if (container?.name == "Address Book") { name = "Google" } else if (container?.name == "Contacts") { name = "Yahoo" } else { name = "Facebook" } return

how to retrive all CNContactStore from device without filter

两盒软妹~` 提交于 2019-12-18 16:33:12
问题 I'm trying to insert into var contacts: [CNContact] = [] the var store = CNContactStore() but I did not find the right code for this job, i found this function that I need to give that a name func findContactsWithName(name: String) { AppDelegate.sharedDelegate().checkAccessStatus({ (accessGranted) -> Void in if accessGranted { dispatch_async(dispatch_get_main_queue(), { () -> Void in do { let predicate: NSPredicate = CNContact.predicateForContactsMatchingName(name) let keysToFetch =

CNContactStoreDidChangeNotification is fired multiple times

时间秒杀一切 提交于 2019-12-18 12:46:04
问题 I am able to observe the CNContactStoreDidChangeNotification when the contact database is changed while the app is in background state. I am pretty sure that only one observer was added to NSNotificationCenter . The problem is NSNotificationCenter posts MULTIPLE times (2, 3, 5, and even more times) even if I only add one new contact. Where is the problem? 回答1: Make certain you aren't adding the observer multiple times. This can happen without you realizing it if (for example) you call