Skip to content

Commit 51028eb

Browse files
authored
Merge pull request #68 from appwrite/dev
fix: pong response & chunked upload
2 parents 5cb7d8e + 9c7fa11 commit 51028eb

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
1+
Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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.6.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.6.1-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)
@@ -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: "7.1.0"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "8.0.0"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "apple",
26-
"x-sdk-version": "7.1.0",
26+
"x-sdk-version": "8.0.0",
2727
"x-appwrite-response-format": "1.6.0"
2828
]
2929

@@ -249,6 +249,26 @@ open class Client {
249249
) ?? ""
250250
}
251251

252+
///
253+
/// Sends a "ping" request to Appwrite to verify connectivity.
254+
///
255+
/// @return String
256+
/// @throws Exception
257+
///
258+
open func ping() async throws -> String {
259+
let apiPath: String = "/ping"
260+
261+
let apiHeaders: [String: String] = [
262+
"content-type": "application/json"
263+
]
264+
265+
return try await call(
266+
method: "GET",
267+
path: apiPath,
268+
headers: apiHeaders
269+
)
270+
}
271+
252272
///
253273
/// Make an API call
254274
///
@@ -319,6 +339,8 @@ open class Client {
319339
}
320340
}
321341

342+
var data = try await response.body.collect(upTo: Int.max)
343+
322344
switch response.status.code {
323345
case 0..<400:
324346
if response.headers["Set-Cookie"].count > 0 {
@@ -331,10 +353,11 @@ open class Client {
331353
switch T.self {
332354
case is Bool.Type:
333355
return true as! T
356+
case is String.Type:
357+
return (data.readString(length: data.readableBytes) ?? "") as! T
334358
case is ByteBuffer.Type:
335-
return try await response.body.collect(upTo: Int.max) as! T
359+
return data as! T
336360
default:
337-
let data = try await response.body.collect(upTo: Int.max)
338361
if data.readableBytes == 0 {
339362
return true as! T
340363
}
@@ -344,7 +367,6 @@ open class Client {
344367
}
345368
default:
346369
var message = ""
347-
var data = try await response.body.collect(upTo: Int.max)
348370
var type = ""
349371

350372
do {
@@ -400,7 +422,7 @@ open class Client {
400422
var offset = 0
401423
var result = [String:Any]()
402424

403-
if idParamName != nil && params[idParamName!] as! String != "unique()" {
425+
if idParamName != nil {
404426
// Make a request to check if a file already exists
405427
do {
406428
let map = try await call(

Sources/Appwrite/Services/Account.swift

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ open class Account: Service {
584584
open func updateMfaChallenge(
585585
challengeId: String,
586586
otp: String
587-
) async throws -> Any {
587+
) async throws -> AppwriteModels.Session {
588588
let apiPath: String = "/account/mfa/challenge"
589589

590590
let apiParams: [String: Any?] = [
@@ -596,11 +596,17 @@ open class Account: Service {
596596
"content-type": "application/json"
597597
]
598598

599+
let converter: (Any) -> AppwriteModels.Session = { response in
600+
return AppwriteModels.Session.from(map: response as! [String: Any])
601+
}
602+
599603
return try await client.call(
600604
method: "PUT",
601605
path: apiPath,
602606
headers: apiHeaders,
603-
params: apiParams )
607+
params: apiParams,
608+
converter: converter
609+
)
604610
}
605611

606612
///
@@ -1599,6 +1605,12 @@ open class Account: Service {
15991605
///
16001606
/// Create push target
16011607
///
1608+
/// Use this endpoint to register a device for push notifications. Provide a
1609+
/// target ID (custom or generated using ID.unique()), a device identifier
1610+
/// (usually a device token), and optionally specify which provider should send
1611+
/// notifications to this target. The target is automatically linked to the
1612+
/// current session and includes device information like brand and model.
1613+
///
16021614
/// @param String targetId
16031615
/// @param String identifier
16041616
/// @param String providerId
@@ -1638,6 +1650,12 @@ open class Account: Service {
16381650
///
16391651
/// Update push target
16401652
///
1653+
/// Update the currently logged in user's push notification target. You can
1654+
/// modify the target's identifier (device token) and provider ID (token,
1655+
/// email, phone etc.). The target must exist and belong to the current user.
1656+
/// If you change the provider ID, notifications will be sent through the new
1657+
/// messaging provider instead.
1658+
///
16411659
/// @param String targetId
16421660
/// @param String identifier
16431661
/// @throws Exception
@@ -1674,6 +1692,10 @@ open class Account: Service {
16741692
///
16751693
/// Delete push target
16761694
///
1695+
/// Delete a push notification target for the currently logged in user. After
1696+
/// deletion, the device will no longer receive push notifications. The target
1697+
/// must exist and belong to the current user.
1698+
///
16771699
/// @param String targetId
16781700
/// @throws Exception
16791701
/// @return array
@@ -1758,9 +1780,7 @@ open class Account: Service {
17581780
/// [POST
17591781
/// /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession)
17601782
/// endpoint to complete the login process. The link sent to the user's email
1761-
/// address is valid for 1 hour. If you are on a mobile device you can leave
1762-
/// the URL parameter empty, so that the login completion will be handled by
1763-
/// your Appwrite instance by default.
1783+
/// address is valid for 1 hour.
17641784
///
17651785
/// A user is limited to 10 active sessions at a time by default. [Learn more
17661786
/// about session

Sources/AppwriteEnums/ImageFormat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public enum ImageFormat: String, CustomStringConvertible {
66
case gif = "gif"
77
case png = "png"
88
case webp = "webp"
9+
case heic = "heic"
910
case avif = "avif"
1011

1112
public var description: String {

docs/examples/account/update-mfa-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let client = Client()
66

77
let account = Account(client)
88

9-
let result = try await account.updateMfaChallenge(
9+
let session = try await account.updateMfaChallenge(
1010
challengeId: "<CHALLENGE_ID>",
1111
otp: "<OTP>"
1212
)

0 commit comments

Comments
 (0)