Skip to content

Commit 4854ed6

Browse files
committed
Update for 1.0.0
1 parent 56f06e6 commit 4854ed6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+343
-83
lines changed

README.md

Lines changed: 145 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.0.0-RC1-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.0.0-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
99

10-
**This SDK is compatible with Appwrite server version 1.0.0-RC1. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).**
10+
**This SDK is compatible with Appwrite server version 1.0.0. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-apple/releases).**
1111

1212
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Apple SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1313

@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.0.0-RC2"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "1.0.0"),
3535
],
3636
```
3737

@@ -48,6 +48,148 @@ Then add it to your target:
4848
```
4949

5050

51+
## Getting Started
52+
53+
### Add your Apple Platform
54+
To initialize your SDK and start interacting with Appwrite services, you need to add a new Apple platform to your project. To add a new platform, go to your Appwrite console, select your project (create one if you haven't already), and click the 'Add Platform' button on the project Dashboard.
55+
56+
From the options, choose to add a new **iOS**, **macOS**, **watchOS** or **tvOS** platform and add your app credentials.
57+
58+
Add your app <u>name</u> and <u>bundle identifier</u>. Your bundle identifier can be found in your Xcode project file or your `Info.plist` file. By registering a new platform, you are allowing your app to communicate with the Appwrite API.
59+
60+
### Registering URL schemes
61+
62+
In order to capture the Appwrite OAuth callback url, the following URL scheme needs to be added to project. You can add this from Xcode by selecting your project file, then the target you wish to use OAuth with. From the `Info` tab, expand the `URL types` section and add your Appwrite instance domain for the `Identifier`, and `appwrite-callback-[PROJECT-ID]` for the `URL scheme`. Be sure to replace the **[PROJECT_ID]** string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in the console. Alternatively, you can add the following block directly to your targets `Info.plist` file:
63+
64+
```xml
65+
<key>CFBundleURLTypes</key>
66+
<array>
67+
<dict>
68+
<key>CFBundleTypeRole</key>
69+
<string>Editor</string>
70+
<key>CFBundleURLName</key>
71+
<string>io.appwrite</string>
72+
<key>CFBundleURLSchemes</key>
73+
<array>
74+
<string>appwrite-callback-[PROJECT-ID]</string>
75+
</array>
76+
</dict>
77+
</array>
78+
```
79+
80+
Next we need to add a hook to save cookies when our app is opened by its callback URL.
81+
82+
### Registering an OAuth handler view
83+
84+
> If you're using UIKit, you can skip this section.
85+
86+
In SwiftUI this is as simple as ensuring `.registerOAuthHanlder()` is called on the `View` you want to invoke an OAuth request from.
87+
88+
### Updating the SceneDelegate for UIKit
89+
90+
> If you're using SwiftUI, you can skip this section.
91+
92+
For UIKit, you need to add the following function to your `SceneDelegate.swift`. If you have already defined this function, you can just add the contents from below.
93+
94+
```swift
95+
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
96+
guard let url = URLContexts.first?.url,
97+
url.absoluteString.contains("appwrite-callback") else {
98+
return
99+
}
100+
WebAuthComponent.handleIncomingCookie(from: url)
101+
}
102+
```
103+
104+
### Init your SDK
105+
106+
Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page.
107+
108+
```swift
109+
import Appwrite
110+
111+
func main() {
112+
let client = Client()
113+
.setEndpoint("http://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
114+
.setProject("5df5acd0d48c2") // Your project ID
115+
.setSelfSigned() // Use only on dev mode with a self-signed SSL cert
116+
}
117+
```
118+
119+
### Make Your First Request
120+
121+
Once your SDK object is initialized, create any of the Appwrite service objects and choose any request to send. Full documentation for any service method you would like to use can be found in your SDK documentation or in the [API References](https://appwrite.io/docs) section.
122+
123+
```swift
124+
let account = Account(client)
125+
126+
do {
127+
let user = try await account.create(
128+
userId: ID.unique(),
129+
email: "[email protected]",
130+
password: "password"
131+
)
132+
print(String(describing: user.toMap()))
133+
} catch {
134+
print(error.localizedDescription)
135+
}
136+
```
137+
138+
### Full Example
139+
140+
```swift
141+
import Appwrite
142+
143+
func main() {
144+
let client = Client()
145+
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
146+
.setProject("5df5acd0d48c2") // Your project ID
147+
.setSelfSigned() // Use only on dev mode with a self-signed SSL cert
148+
149+
let account = Account(client)
150+
151+
do {
152+
let user = try await account.create(
153+
userId: ID.unique(),
154+
email: "[email protected]",
155+
password: "password"
156+
)
157+
print(String(describing: account.toMap()))
158+
} catch {
159+
print(error.localizedDescription)
160+
}
161+
}
162+
```
163+
164+
### Error Handling
165+
166+
When an error occurs, the Appwrite Apple SDK throws an `AppwriteError` object with `message` and `code` properties. You can handle any errors in a catch block and present the `message` or `localizedDescription` to the user or handle it yourself based on the provided error information. Below is an example.
167+
168+
```swift
169+
import Appwrite
170+
171+
func main() {
172+
let account = Account(client)
173+
174+
do {
175+
let user = try await account.get()
176+
print(String(describing: user.toMap()))
177+
} catch {
178+
print(error.localizedDescription)
179+
}
180+
}
181+
```
182+
183+
### Learn more
184+
185+
You can use the following resources to learn more and get help
186+
187+
- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-server)
188+
- 📜 [Appwrite Docs](https://appwrite.io/docs)
189+
- 💬 [Discord Community](https://appwrite.io/discord)
190+
- 🚂 [Appwrite Swift Playground](https://github.com/appwrite/playground-for-swift-server)
191+
192+
51193
## Contribution
52194

53195
This library is auto-generated by Appwrite custom [SDK Generator](https://github.com/appwrite/sdk-generator). To learn more about how you can help us improve this SDK, please check the [contribution guide](https://github.com/appwrite/sdk-generator/blob/master/CONTRIBUTING.md) before sending a pull-request.

Sources/Appwrite/Client.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "swiftclient",
26-
"x-sdk-version": "1.0.0-RC2",
27-
"X-Appwrite-Response-Format": "1.0.0-RC1"
26+
"x-sdk-version": "1.0.0",
27+
"X-Appwrite-Response-Format": "1.0.0"
2828
]
2929

3030
open var config: [String: String] = [:]

Sources/Appwrite/Role.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ public class Role {
33
return "any"
44
}
55

6-
public static func user(_ id: String) -> String {
7-
return "user:\(id)"
6+
public static func user(_ id: String, _ status: String = "") -> String {
7+
if(status.isEmpty) {
8+
return "user:\(id)"
9+
}
10+
return "user:\(id)/\(status)"
811
}
912

10-
public static func users() -> String {
11-
return "users"
13+
public static func users(_ status: String = "") -> String {
14+
if(status.isEmpty) {
15+
return "users"
16+
}
17+
return "users/\(status)"
1218
}
1319

1420
public static func guests() -> String {
@@ -22,6 +28,10 @@ public class Role {
2228
return "team:\(id)/\(role)"
2329
}
2430

31+
public static func member(_ id: String) -> String {
32+
return "member:\(id)"
33+
}
34+
2535
public static func status(_ status: String) -> String {
2636
return "status:\(status)"
2737
}

Sources/Appwrite/Services/Account.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ open class Account: Service {
153153
}
154154

155155
///
156-
/// Get Account Logs
156+
/// List Account Logs
157157
///
158158
/// Get currently logged in user list of latest security activity logs. Each
159159
/// log returns user IP address, location and date and time of log.
@@ -162,7 +162,7 @@ open class Account: Service {
162162
/// @throws Exception
163163
/// @return array
164164
///
165-
open func getLogs(
165+
open func listLogs(
166166
queries: [String]? = nil
167167
) async throws -> AppwriteModels.LogList {
168168
let path: String = "/account/logs"
@@ -447,15 +447,15 @@ open class Account: Service {
447447
}
448448

449449
///
450-
/// Get Account Sessions
450+
/// List Account Sessions
451451
///
452452
/// Get currently logged in user list of active sessions across different
453453
/// devices.
454454
///
455455
/// @throws Exception
456456
/// @return array
457457
///
458-
open func getSessions(
458+
open func listSessions(
459459
) async throws -> AppwriteModels.SessionList {
460460
let path: String = "/account/sessions"
461461
let params: [String: Any?] = [:]
@@ -1209,7 +1209,7 @@ open class Account: Service {
12091209
}
12101210

12111211
///
1212-
/// Get Account Logs
1212+
/// List Account Logs
12131213
///
12141214
/// Get currently logged in user list of latest security activity logs. Each
12151215
/// log returns user IP address, location and date and time of log.
@@ -1219,13 +1219,13 @@ open class Account: Service {
12191219
/// @return array
12201220
///
12211221
@available(*, deprecated, message: "Use the async overload instead")
1222-
open func getLogs(
1222+
open func listLogs(
12231223
queries: [String]? = nil,
12241224
completion: ((Result<AppwriteModels.LogList, AppwriteError>) -> Void)? = nil
12251225
) {
12261226
Task {
12271227
do {
1228-
let result = try await getLogs(
1228+
let result = try await listLogs(
12291229
queries: queries
12301230
)
12311231
completion?(.success(result))
@@ -1456,7 +1456,7 @@ open class Account: Service {
14561456
}
14571457

14581458
///
1459-
/// Get Account Sessions
1459+
/// List Account Sessions
14601460
///
14611461
/// Get currently logged in user list of active sessions across different
14621462
/// devices.
@@ -1465,12 +1465,12 @@ open class Account: Service {
14651465
/// @return array
14661466
///
14671467
@available(*, deprecated, message: "Use the async overload instead")
1468-
open func getSessions(
1468+
open func listSessions(
14691469
completion: ((Result<AppwriteModels.SessionList, AppwriteError>) -> Void)? = nil
14701470
) {
14711471
Task {
14721472
do {
1473-
let result = try await getSessions(
1473+
let result = try await listSessions(
14741474
)
14751475
completion?(.success(result))
14761476
} catch {

0 commit comments

Comments
 (0)