{"id":26281064,"url":"https://github.com/yonat/contactschangenotifier","last_synced_at":"2025-05-07T05:10:37.736Z","repository":{"id":45709179,"uuid":"513916884","full_name":"yonat/ContactsChangeNotifier","owner":"yonat","description":"Which contacts changed outside your iOS app? Better CNContactStoreDidChange notification: Get real changes, without the noise.","archived":false,"fork":false,"pushed_at":"2024-10-20T19:18:19.000Z","size":159,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-16T04:24:01.131Z","etag":null,"topics":["cncontact","cncontactstore","contacts","ios","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yonat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["yonat"]}},"created_at":"2022-07-14T13:41:39.000Z","updated_at":"2025-02-23T20:28:30.000Z","dependencies_parsed_at":"2024-11-02T10:30:46.298Z","dependency_job_id":"00461606-586b-486d-bff7-a4c1a8ef695f","html_url":"https://github.com/yonat/ContactsChangeNotifier","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"c33b39aab3d06e98a23d29e329ab15d23bf10414"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FContactsChangeNotifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FContactsChangeNotifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FContactsChangeNotifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonat%2FContactsChangeNotifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yonat","download_url":"https://codeload.github.com/yonat/ContactsChangeNotifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817633,"owners_count":21808706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cncontact","cncontactstore","contacts","ios","swift"],"created_at":"2025-03-14T15:19:01.324Z","updated_at":"2025-05-07T05:10:37.716Z","avatar_url":"https://github.com/yonat.png","language":"Swift","funding_links":["https://github.com/sponsors/yonat"],"categories":[],"sub_categories":[],"readme":"# ContactsChangeNotifier\n\nWhich contacts changed outside your iOS app? Better `CNContactStoreDidChange` notification: Get real changes, without the noise.\n\n[![Swift Version][swift-image]][swift-url]\n[![License][license-image]][license-url]\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/ContactsChangeNotifier.svg)](https://img.shields.io/cocoapods/v/ContactsChangeNotifier.svg)\n[![Platform](https://img.shields.io/cocoapods/p/ContactsChangeNotifier.svg?style=flat)](http://cocoapods.org/pods/ContactsChangeNotifier)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n\n## Why Oh Why\n\nSadly, the Contacts changes API is a mess:\n\n- The `CNContactStoreDidChange` notification is received for changes your own code did, not just outside your app. 🤷\n- It contains undocumented `userInfo` fields. 🙈\n- To get the actual changes, you need to use an Objective-C API that is not even callable from Swift. 😱\n- That API is easy to get wrong, and requires maintaining opaque state, or receiving the complete changes history. 🧨\n\nIt’s the API that time forgot. 🧟‍♂️\n\n## ContactsChangeNotifier Features\n\n* Only get notified for changes outside your app. 🎯\n* Get the list of changes included in the notification. 🎁\n* Only get changes since last notification, not the full all-time history. ✨\n* No Objective-C required. 💥\n\n## Usage\n\n1. Get the user's Contacts access permission (see [docs](https://developer.apple.com/documentation/contacts/requesting_authorization_to_access_contacts)).\n2. Keep a `ContactsChangeNotifier` instance -\n   it will observe all Contacts changes but post only those that from outside your app.   \n3. Observe `ContactsChangeNotifier.didChangeNotification` notification.\n4. See change events in the notification's `contactsChangeEvents`.\n\n```swift\n// 2. Keep a ContactsChangeNotifier instance\nlet contactsChangeNotifier = try! ContactsChangeNotifier(\n    store: myCNContactStore,\n    fetchRequest: .fetchRequest(additionalContactKeyDescriptors: myCNKeyDescriptors)\n)\n\n// 3. Observe ContactsChangeNotifier.didChangeNotification notification\nlet observation = NotificationCenter.default.addObserver(\n    forName: ContactsChangeNotifier.didChangeNotification,\n    object: nil,\n    queue: nil\n) { notification in\n    // 4. See change events in the notification's contactsChangeEvents\n    for event in notification.contactsChangeEvents ?? [] {\n        switch event {\n        case let addEvent as CNChangeHistoryAddContactEvent:\n            print(addEvent.contact)\n        case let updateEvent as CNChangeHistoryUpdateContactEvent:\n            print(updateEvent.contact)\n        case let deleteEvent as CNChangeHistoryDeleteContactEvent:\n            print(deleteEvent.contactIdentifier)\n        default:\n            // group event\n            break\n        }\n    }\n}\n```\n\n## Installation\n\n### CocoaPods:\n\n```ruby\npod 'ContactsChangeNotifier'\n```\n\n### Swift Package Manager:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/yonat/ContactsChangeNotifier\", from: \"1.2.0\")\n]\n```\n\n[swift-image]:https://img.shields.io/badge/swift-5.0-orange.svg\n[swift-url]: https://swift.org/\n[license-image]: https://img.shields.io/badge/License-MIT-blue.svg\n[license-url]: LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonat%2Fcontactschangenotifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyonat%2Fcontactschangenotifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonat%2Fcontactschangenotifier/lists"}