You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-5Lines changed: 31 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,15 @@
11
11
12
12
`FSContactStore` is a Swift package that provides a convenient and easy-to-use interface for interacting with Apple's `Contacts` framework on iOS and macOS.
13
13
14
-
## Features:
14
+
## Features
15
15
16
16
* Simplified authorization handling for requesting access to contacts.
17
17
* Flexible fetching options for retrieving contacts with filtering, sorting, and specifying properties to retrieve.
18
18
* Support for unified contacts, which combine information from multiple sources.
19
19
* Shared instance for quick access to common functionalities.
20
20
* Customizable save requests to allow tailoring logic for adding, updating, and deleting contacts.
21
21
22
-
## Installation:
22
+
## Installation
23
23
24
24
Add the package to your Package.swift file:
25
25
@@ -35,7 +35,7 @@ Import the package in your Swift files:
35
35
importContactStore
36
36
```
37
37
38
-
## Usage:
38
+
## Usage
39
39
40
40
1. Import the library:
41
41
@@ -120,7 +120,7 @@ try store.delete(contact)
120
120
121
121
By default, `ContactStore` uses a standard `CNSaveRequest` instance.
122
122
You can modify the static closure `ContactStore.makeCNSaveRequest` to inject custom logic or provide different request implementations.
123
-
**Important:** To modify the ContactStore.makeCNSaveRequest closure, you must use the use(_:) method.
123
+
**Important:** To modify the `ContactStore.makeCNSaveRequest` closure, you must use the `use(_:)` method.
124
124
125
125
```swift
126
126
ContactStore.use { request in
@@ -133,7 +133,33 @@ ContactStore.use { request in
133
133
This code updates the `ContactStore.makeCNSaveRequest` closure to accept a `CNSaveRequest` instance as an argument,
134
134
make any necessary changes to it, and then return the updated request.
135
135
136
-
## Contributions:
136
+
7. Customizing Authorization Status (Optional):
137
+
138
+
By default, `ContactStore` uses the actual authorization status from the system's `CNContactStore`.
139
+
However, you can override this behavior with a custom closure to inject specific authorization statuses for testing or other purposes.
140
+
141
+
Here's how to customize the authorization status:
142
+
143
+
**Use the `use(_:)` method:**
144
+
145
+
- Call the `use(_:)` method on `ContactStore` to provide a custom closure for creating `CNAuthorizationStatus` instances.
146
+
- The closure accepts no arguments and returns a `CNAuthorizationStatus` value.
147
+
148
+
**Implement the closure logic:**
149
+
150
+
- Within the closure, specify the desired authorization status to be returned.
151
+
You can return a fixed value or implement more complex logic based on your needs.
152
+
153
+
```swift
154
+
ContactStore.use {
155
+
return .denied// Simulate denied authorization status
156
+
}
157
+
158
+
let currentStatus = ContactStore.authorizationStatus()
159
+
// currentStatus will now be .denied
160
+
```
161
+
162
+
## Contributions
137
163
138
164
We welcome contributions to this project! Please feel free to open issues or pull requests to help improve the package.
0 commit comments