From adbb8c1559e0334bfbb7bfb67f21693a6c758bb6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 21 Feb 2024 23:35:47 +1300 Subject: [PATCH] Release candidate 4 for 1.5.x --- README.md | 4 +- Sources/Appwrite/Client.swift | 2 +- Sources/Appwrite/Services/Messaging.swift | 8 +- docs/examples/account/create-email-token.md | 3 +- .../account/create-magic-u-r-l-token.md | 4 +- .../examples/account/create-o-auth2session.md | 6 +- docs/examples/account/create-push-target.md | 3 +- docs/examples/account/create.md | 3 +- docs/examples/account/list-identities.md | 4 +- docs/examples/account/list-logs.md | 4 +- docs/examples/account/update-m-f-a.md | 2 +- docs/examples/account/update-password.md | 3 +- docs/examples/avatars/get-browser.md | 5 +- docs/examples/avatars/get-credit-card.md | 5 +- docs/examples/avatars/get-flag.md | 5 +- docs/examples/avatars/get-image.md | 4 +- docs/examples/avatars/get-initials.md | 7 +- docs/examples/avatars/get-q-r.md | 5 +- docs/examples/databases/create-document.md | 3 +- docs/examples/databases/get-document.md | 3 +- docs/examples/databases/list-documents.md | 3 +- docs/examples/databases/update-document.md | 4 +- docs/examples/functions/create-execution.md | 7 +- docs/examples/functions/list-executions.md | 4 +- docs/examples/storage/create-file.md | 3 +- docs/examples/storage/get-file-preview.md | 13 ++- docs/examples/storage/list-files.md | 4 +- docs/examples/storage/update-file.md | 4 +- docs/examples/teams/create-membership.md | 7 +- docs/examples/teams/create.md | 3 +- docs/examples/teams/list-memberships.md | 4 +- docs/examples/teams/list.md | 5 +- .../Example.xcodeproj/project.pbxproj | 84 +++++++++++++++++-- example-swiftui/Shared/ExampleApp.swift | 74 ++++++++++++++-- example-swiftui/Shared/ExampleView.swift | 2 +- example-swiftui/Shared/ExampleViewModel.swift | 83 +++++++++++------- example-swiftui/test (iOS).entitlements | 8 ++ example-swiftui/test (tvOS).entitlements | 8 ++ example-swiftui/test (watchOS).entitlements | 8 ++ 39 files changed, 330 insertions(+), 81 deletions(-) create mode 100644 example-swiftui/test (iOS).entitlements create mode 100644 example-swiftui/test (tvOS).entitlements create mode 100644 example-swiftui/test (watchOS).entitlements diff --git a/README.md b/README.md index 6d30697..55d9a2b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square) ![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.4.13-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.5.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![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: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "5.0.0-rc.3"), + .package(url: "git@github.com:appwrite/sdk-for-apple.git", from: "5.0.0-rc.4"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index d3382f6..24e8903 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -25,7 +25,7 @@ open class Client { "x-sdk-name": "Apple", "x-sdk-platform": "client", "x-sdk-language": "apple", - "x-sdk-version": "5.0.0-rc.3", + "x-sdk-version": "5.0.0-rc.4", "x-appwrite-response-format": "1.5.0" ] diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index 48247cb..13f9227 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -9,7 +9,9 @@ import AppwriteModels open class Messaging: Service { /// - /// Create a subscriber. + /// Create a subscriber + /// + /// Create a new subscriber. /// /// @param String topicId /// @param String subscriberId @@ -48,7 +50,9 @@ open class Messaging: Service { } /// - /// Delete a subscriber. + /// Delete a subscriber + /// + /// Delete a subscriber by its unique ID. /// /// @param String topicId /// @param String subscriberId diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md index ab674d5..9237a70 100644 --- a/docs/examples/account/create-email-token.md +++ b/docs/examples/account/create-email-token.md @@ -8,6 +8,7 @@ let account = Account(client) let token = try await account.createEmailToken( userId: "[USER_ID]", - email: "email@example.com" + email: "email@example.com", + phrase: false // optional ) diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-u-r-l-token.md index d802274..9b94291 100644 --- a/docs/examples/account/create-magic-u-r-l-token.md +++ b/docs/examples/account/create-magic-u-r-l-token.md @@ -8,6 +8,8 @@ let account = Account(client) let token = try await account.createMagicURLToken( userId: "[USER_ID]", - email: "email@example.com" + email: "email@example.com", + url: "https://example.com", // optional + phrase: false // optional ) diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth2session.md index a00dfc5..83b419a 100644 --- a/docs/examples/account/create-o-auth2session.md +++ b/docs/examples/account/create-o-auth2session.md @@ -8,6 +8,10 @@ let client = Client() let account = Account(client) let success = try await account.createOAuth2Session( - provider: .amazon + provider: .amazon, + success: "https://example.com", // optional + failure: "https://example.com", // optional + token: false, // optional + scopes: [] // optional ) diff --git a/docs/examples/account/create-push-target.md b/docs/examples/account/create-push-target.md index 4411eba..69afaab 100644 --- a/docs/examples/account/create-push-target.md +++ b/docs/examples/account/create-push-target.md @@ -8,6 +8,7 @@ let account = Account(client) let target = try await account.createPushTarget( targetId: "[TARGET_ID]", - identifier: "[IDENTIFIER]" + identifier: "[IDENTIFIER]", + providerId: "[PROVIDER_ID]" // optional ) diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index a7836f8..4db8925 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -9,6 +9,7 @@ let account = Account(client) let user = try await account.create( userId: "[USER_ID]", email: "email@example.com", - password: "" + password: "", + name: "[NAME]" // optional ) diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index 86d713c..da9592c 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -6,5 +6,7 @@ let client = Client() let account = Account(client) -let identityList = try await account.listIdentities() +let identityList = try await account.listIdentities( + queries: [] // optional +) diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 0c97255..a90e2cb 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -6,5 +6,7 @@ let client = Client() let account = Account(client) -let logList = try await account.listLogs() +let logList = try await account.listLogs( + queries: [] // optional +) diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-m-f-a.md index e43b5c5..82fded7 100644 --- a/docs/examples/account/update-m-f-a.md +++ b/docs/examples/account/update-m-f-a.md @@ -7,6 +7,6 @@ let client = Client() let account = Account(client) let user = try await account.updateMFA( - mfa: `false` + mfa: false ) diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index bb3c3b0..cf27be3 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -7,6 +7,7 @@ let client = Client() let account = Account(client) let user = try await account.updatePassword( - password: "" + password: "", + oldPassword: "password" // optional ) diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 7a9b381..0c4a194 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -8,6 +8,9 @@ let client = Client() let avatars = Avatars(client) let bytes = try await avatars.getBrowser( - code: .avantBrowser + code: .avantBrowser, + width: 0, // optional + height: 0, // optional + quality: 0 // optional ) diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 6a8b6df..08a8930 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -8,6 +8,9 @@ let client = Client() let avatars = Avatars(client) let bytes = try await avatars.getCreditCard( - code: .americanExpress + code: .americanExpress, + width: 0, // optional + height: 0, // optional + quality: 0 // optional ) diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index bc182e8..22d77fd 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -8,6 +8,9 @@ let client = Client() let avatars = Avatars(client) let bytes = try await avatars.getFlag( - code: .afghanistan + code: .afghanistan, + width: 0, // optional + height: 0, // optional + quality: 0 // optional ) diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index c82dd6c..13e756a 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -7,6 +7,8 @@ let client = Client() let avatars = Avatars(client) let bytes = try await avatars.getImage( - url: "https://example.com" + url: "https://example.com", + width: 0, // optional + height: 0 // optional ) diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index 914ba60..71688fd 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -6,5 +6,10 @@ let client = Client() let avatars = Avatars(client) -let bytes = try await avatars.getInitials() +let bytes = try await avatars.getInitials( + name: "[NAME]", // optional + width: 0, // optional + height: 0, // optional + background: "" // optional +) diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index 5cf329b..c3d5995 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -7,6 +7,9 @@ let client = Client() let avatars = Avatars(client) let bytes = try await avatars.getQR( - text: "[TEXT]" + text: "[TEXT]", + size: 1, // optional + margin: 0, // optional + download: false // optional ) diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 533bbd5..fcff380 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -10,6 +10,7 @@ let document = try await databases.createDocument( databaseId: "[DATABASE_ID]", collectionId: "[COLLECTION_ID]", documentId: "[DOCUMENT_ID]", - data: [:] + data: [:], + permissions: ["read("any")"] // optional ) diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 53b71fb..c6b92d0 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -9,6 +9,7 @@ let databases = Databases(client) let document = try await databases.getDocument( databaseId: "[DATABASE_ID]", collectionId: "[COLLECTION_ID]", - documentId: "[DOCUMENT_ID]" + documentId: "[DOCUMENT_ID]", + queries: [] // optional ) diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 0b375df..3690333 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -8,6 +8,7 @@ let databases = Databases(client) let documentList = try await databases.listDocuments( databaseId: "[DATABASE_ID]", - collectionId: "[COLLECTION_ID]" + collectionId: "[COLLECTION_ID]", + queries: [] // optional ) diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 5a943af..48ef74d 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -9,6 +9,8 @@ let databases = Databases(client) let document = try await databases.updateDocument( databaseId: "[DATABASE_ID]", collectionId: "[COLLECTION_ID]", - documentId: "[DOCUMENT_ID]" + documentId: "[DOCUMENT_ID]", + data: [:], // optional + permissions: ["read("any")"] // optional ) diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 93702bf..436c7c7 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -7,6 +7,11 @@ let client = Client() let functions = Functions(client) let execution = try await functions.createExecution( - functionId: "[FUNCTION_ID]" + functionId: "[FUNCTION_ID]", + body: "[BODY]", // optional + async: false, // optional + path: "[PATH]", // optional + method: .gET, // optional + headers: [:] // optional ) diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index 0f18295..2cc3743 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -7,6 +7,8 @@ let client = Client() let functions = Functions(client) let executionList = try await functions.listExecutions( - functionId: "[FUNCTION_ID]" + functionId: "[FUNCTION_ID]", + queries: [], // optional + search: "[SEARCH]" // optional ) diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index f882420..5cc49a9 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -9,6 +9,7 @@ let storage = Storage(client) let file = try await storage.createFile( bucketId: "[BUCKET_ID]", fileId: "[FILE_ID]", - file: InputFile.fromPath("file.png") + file: InputFile.fromPath("file.png"), + permissions: ["read("any")"] // optional ) diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index e396946..2f7ff52 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -8,6 +8,17 @@ let storage = Storage(client) let bytes = try await storage.getFilePreview( bucketId: "[BUCKET_ID]", - fileId: "[FILE_ID]" + fileId: "[FILE_ID]", + width: 0, // optional + height: 0, // optional + gravity: .center, // optional + quality: 0, // optional + borderWidth: 0, // optional + borderColor: "", // optional + borderRadius: 0, // optional + opacity: 0, // optional + rotation: -360, // optional + background: "", // optional + output: .jpg // optional ) diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 51f7fe8..78fdeb7 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -7,6 +7,8 @@ let client = Client() let storage = Storage(client) let fileList = try await storage.listFiles( - bucketId: "[BUCKET_ID]" + bucketId: "[BUCKET_ID]", + queries: [], // optional + search: "[SEARCH]" // optional ) diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 13bf635..035b0d7 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -8,6 +8,8 @@ let storage = Storage(client) let file = try await storage.updateFile( bucketId: "[BUCKET_ID]", - fileId: "[FILE_ID]" + fileId: "[FILE_ID]", + name: "[NAME]", // optional + permissions: ["read("any")"] // optional ) diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 6de7074..f7537e8 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -8,6 +8,11 @@ let teams = Teams(client) let membership = try await teams.createMembership( teamId: "[TEAM_ID]", - roles: [] + roles: [], + email: "email@example.com", // optional + userId: "[USER_ID]", // optional + phone: "+12065550100", // optional + url: "https://example.com", // optional + name: "[NAME]" // optional ) diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index c28eec4..95892d7 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -8,6 +8,7 @@ let teams = Teams(client) let team = try await teams.create( teamId: "[TEAM_ID]", - name: "[NAME]" + name: "[NAME]", + roles: [] // optional ) diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 1f8a0cc..91af134 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -7,6 +7,8 @@ let client = Client() let teams = Teams(client) let membershipList = try await teams.listMemberships( - teamId: "[TEAM_ID]" + teamId: "[TEAM_ID]", + queries: [], // optional + search: "[SEARCH]" // optional ) diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index 72226d4..1446249 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -6,5 +6,8 @@ let client = Client() let teams = Teams(client) -let teamList = try await teams.list() +let teamList = try await teams.list( + queries: [], // optional + search: "[SEARCH]" // optional +) diff --git a/example-swiftui/Example.xcodeproj/project.pbxproj b/example-swiftui/Example.xcodeproj/project.pbxproj index 86eb0e8..142cd62 100644 --- a/example-swiftui/Example.xcodeproj/project.pbxproj +++ b/example-swiftui/Example.xcodeproj/project.pbxproj @@ -26,7 +26,11 @@ 1D54699029932DF900AAB591 /* ExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D34C2522702E4A000D1DA8D /* ExampleViewModel.swift */; }; 1D54699129932DF900AAB591 /* ExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D34C2542702E4B500D1DA8D /* ExampleView.swift */; }; 1D54699229932E0500AAB591 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B115883E8645C18835765B2 /* Assets.xcassets */; }; - 1DB55D6D2B6E091400E119EF /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DB55D6C2B6E091400E119EF /* GoogleService-Info.plist */; }; + 1DB1714C2B84402E00318590 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 1DB1714B2B84402E00318590 /* FirebaseMessaging */; }; + 1DB1714E2B84403C00318590 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 1DB1714D2B84403C00318590 /* FirebaseMessaging */; }; + 1DB171502B84404500318590 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 1DB1714F2B84404500318590 /* FirebaseMessaging */; }; + 1DB171522B84404E00318590 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = 1DB171512B84404E00318590 /* FirebaseMessaging */; }; + 1DB171592B8458B700318590 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 1DB171582B8458B600318590 /* GoogleService-Info.plist */; }; 1DBB414827E87CA000ECF86F /* Appwrite in Frameworks */ = {isa = PBXBuildFile; productRef = 1DBB414727E87CA000ECF86F /* Appwrite */; }; 1DBB414A27E87CA800ECF86F /* Appwrite in Frameworks */ = {isa = PBXBuildFile; productRef = 1DBB414927E87CA800ECF86F /* Appwrite */; }; 2358B1EE270AC9DC0016EFBA /* ExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D34C2522702E4A000D1DA8D /* ExampleViewModel.swift */; }; @@ -83,7 +87,10 @@ 1D43900726FC8B2500C71E3E /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = ""; }; 1D54695829932D3500AAB591 /* test (watchOS).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "test (watchOS).app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1D54697429932D3700AAB591 /* Test watchOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Test watchOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 1DB55D6C2B6E091400E119EF /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 1DB171552B8457B100318590 /* test (iOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "test (iOS).entitlements"; sourceTree = ""; }; + 1DB171582B8458B600318590 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 1DB1715A2B845EAB00318590 /* test (tvOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "test (tvOS).entitlements"; sourceTree = ""; }; + 1DB1715B2B845EB800318590 /* test (watchOS).entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "test (watchOS).entitlements"; sourceTree = ""; }; 1DBB414627E87BDB00ECF86F /* apple */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = apple; path = ../../../examples/apple; sourceTree = ""; }; 23DDF5922709A457006EFAFA /* ImagePicker+iOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ImagePicker+iOS.swift"; sourceTree = ""; }; 23DDF5942709A46A006EFAFA /* ImagePicker+macOS.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ImagePicker+macOS.swift"; sourceTree = ""; }; @@ -108,6 +115,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1DB171502B84404500318590 /* FirebaseMessaging in Frameworks */, 1D0647F92991E16D00ADFADC /* Appwrite in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -123,6 +131,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1DB171522B84404E00318590 /* FirebaseMessaging in Frameworks */, 1D54698A29932D9100AAB591 /* Appwrite in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -152,6 +161,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1DB1714E2B84403C00318590 /* FirebaseMessaging in Frameworks */, 1DBB414A27E87CA800ECF86F /* Appwrite in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -160,6 +170,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1DB1714C2B84402E00318590 /* FirebaseMessaging in Frameworks */, 1DBB414827E87CA000ECF86F /* Appwrite in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -207,7 +218,10 @@ 4B1152396B94D0F596CEBB52 = { isa = PBXGroup; children = ( - 1DB55D6C2B6E091400E119EF /* GoogleService-Info.plist */, + 1DB1715B2B845EB800318590 /* test (watchOS).entitlements */, + 1DB1715A2B845EAB00318590 /* test (tvOS).entitlements */, + 1DB171582B8458B600318590 /* GoogleService-Info.plist */, + 1DB171552B8457B100318590 /* test (iOS).entitlements */, 1DBB414527E87BDB00ECF86F /* Packages */, 4B115B49441350FF784C7745 /* Products */, 4B11566FD1E1FA1ABD88E438 /* Shared */, @@ -305,6 +319,7 @@ name = "test (tvOS)"; packageProductDependencies = ( 1D0647F82991E16D00ADFADC /* Appwrite */, + 1DB1714F2B84404500318590 /* FirebaseMessaging */, ); productName = Test; productReference = 1D0647BD2991E01C00ADFADC /* test (tvOS).app */; @@ -343,6 +358,7 @@ name = "test (watchOS)"; packageProductDependencies = ( 1D54698929932D9100AAB591 /* Appwrite */, + 1DB171512B84404E00318590 /* FirebaseMessaging */, ); productName = "test Watch App"; productReference = 1D54695829932D3500AAB591 /* test (watchOS).app */; @@ -381,6 +397,7 @@ name = "test (iOS)"; packageProductDependencies = ( 1DBB414727E87CA000ECF86F /* Appwrite */, + 1DB1714B2B84402E00318590 /* FirebaseMessaging */, ); productName = "test (iOS)"; productReference = 4B115DA4916DAA4E8F13734F /* test.app */; @@ -401,6 +418,7 @@ name = "test (macOS)"; packageProductDependencies = ( 1DBB414927E87CA800ECF86F /* Appwrite */, + 1DB1714D2B84403C00318590 /* FirebaseMessaging */, ); productName = "test (macOS)"; productReference = 4B11505C9899942E695B59FF /* test.app */; @@ -481,6 +499,9 @@ en, ); mainGroup = 4B1152396B94D0F596CEBB52; + packageReferences = ( + 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, + ); productRefGroup = 4B115B49441350FF784C7745 /* Products */; projectDirPath = ""; projectRoot = ""; @@ -548,7 +569,7 @@ buildActionMask = 2147483647; files = ( 4B1157C67CF5E569FBCB65DD /* Assets.xcassets in Resources */, - 1DB55D6D2B6E091400E119EF /* GoogleService-Info.plist in Resources */, + 1DB171592B8458B700318590 /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -675,6 +696,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = "test (tvOS).entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; ENABLE_PREVIEWS = YES; @@ -702,6 +724,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = "App Icon & Top Shelf Image"; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = "test (tvOS).entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; ENABLE_PREVIEWS = YES; @@ -771,6 +794,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = "test (watchOS).entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; ENABLE_PREVIEWS = YES; @@ -800,6 +824,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CODE_SIGN_ENTITLEMENTS = "test (watchOS).entitlements"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; ENABLE_PREVIEWS = YES; @@ -905,7 +930,10 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = GWZ23QTYB5; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = macOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -915,6 +943,7 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = io.appwrite.mac; PRODUCT_NAME = test; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx; SWIFT_VERSION = 5.0; }; @@ -925,14 +954,16 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "test (iOS).entitlements"; + DEVELOPMENT_TEAM = GWZ23QTYB5; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iOS/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = io.appwrite.ios; + PRODUCT_BUNDLE_IDENTIFIER = "io.appwrite.ios-example"; PRODUCT_NAME = test; SDKROOT = iphoneos; SWIFT_VERSION = 5.0; @@ -963,14 +994,16 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = "test (iOS).entitlements"; + DEVELOPMENT_TEAM = GWZ23QTYB5; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iOS/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 15.0; + IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = io.appwrite.ios; + PRODUCT_BUNDLE_IDENTIFIER = "io.appwrite.ios-example"; PRODUCT_NAME = test; SDKROOT = iphoneos; SWIFT_VERSION = 5.0; @@ -984,7 +1017,10 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = GWZ23QTYB5; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = macOS/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -994,6 +1030,7 @@ MACOSX_DEPLOYMENT_TARGET = 11.0; PRODUCT_BUNDLE_IDENTIFIER = io.appwrite.mac; PRODUCT_NAME = test; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx; SWIFT_VERSION = 5.0; }; @@ -1213,6 +1250,17 @@ }; /* End XCConfigurationList section */ +/* Begin XCRemoteSwiftPackageReference section */ + 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/firebase/firebase-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 10.21.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + /* Begin XCSwiftPackageProductDependency section */ 1D0647F82991E16D00ADFADC /* Appwrite */ = { isa = XCSwiftPackageProductDependency; @@ -1222,6 +1270,26 @@ isa = XCSwiftPackageProductDependency; productName = Appwrite; }; + 1DB1714B2B84402E00318590 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; + 1DB1714D2B84403C00318590 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; + 1DB1714F2B84404500318590 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; + 1DB171512B84404E00318590 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = 1DB171482B84400300318590 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; 1DBB414727E87CA000ECF86F /* Appwrite */ = { isa = XCSwiftPackageProductDependency; productName = Appwrite; diff --git a/example-swiftui/Shared/ExampleApp.swift b/example-swiftui/Shared/ExampleApp.swift index 3c40ad3..15ff0c9 100644 --- a/example-swiftui/Shared/ExampleApp.swift +++ b/example-swiftui/Shared/ExampleApp.swift @@ -1,29 +1,87 @@ import SwiftUI import Appwrite import NIO +import Firebase +import FirebaseMessaging + +let host = "https://cloud.appwrite.io/v1" +let projectId = "[YOUR_PROJECT_ID]" + +let client = Client() + .setEndpoint(host) + .setProject(projectId) + +let account = Account(client) +let storage = Storage(client) +let realtime = Realtime(client) + +class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate { -class AppDelegate: NSObject, UIApplicationDelegate, AppwriteDelegate { func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil ) -> Bool { - NotificationHandler.shared.setup(application, delegate: self, provider: .apns) + FirebaseApp.configure() + + Messaging.messaging().delegate = self + + UNUserNotificationCenter.current().delegate = self + + let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound] + UNUserNotificationCenter.current().requestAuthorization( + options: authOptions, + completionHandler: { granted, error in + DispatchQueue.main.async { + if granted { + application.registerForRemoteNotifications() + } + } + } + ) return true } - func application( - _ application: UIApplication, - didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data + func messaging( + _ messaging: FirebaseMessaging.Messaging, + didReceiveRegistrationToken fcmToken: String? ) { - NotificationHandler.shared.handleAPNSToken(deviceToken) + guard let fcmToken = fcmToken else { + return + } + + UserDefaults.standard.set(fcmToken , forKey: "fcmToken") + + let targetId = UserDefaults.standard.string(forKey: "targetId") + + Task { + do { + _ = try await account.get() + } catch { + return + } + + if targetId == nil { + let target = try? await account.createPushTarget( + targetId: ID.unique(), + identifier: fcmToken + ) + + UserDefaults.standard.set(target?.id , forKey: "targetId") + } else { + _ = try? await account.updatePushTarget( + targetId: targetId!, + identifier: fcmToken + ) + } + } } func application( _ application: UIApplication, - didFailToRegisterForRemoteNotificationsWithError error: Error + didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { - print(error) + Messaging.messaging().apnsToken = deviceToken } } diff --git a/example-swiftui/Shared/ExampleView.swift b/example-swiftui/Shared/ExampleView.swift index c1a93e7..d2f6354 100644 --- a/example-swiftui/Shared/ExampleView.swift +++ b/example-swiftui/Shared/ExampleView.swift @@ -17,7 +17,7 @@ struct ExampleView: View { .aspectRatio(contentMode: .fit) .frame(height: 200) - TextField("", text: $viewModel.response) + TextField("", text: $viewModel.response, axis: .vertical) .padding() Button("Login") { diff --git a/example-swiftui/Shared/ExampleViewModel.swift b/example-swiftui/Shared/ExampleViewModel.swift index 6fcfaff..817a906 100644 --- a/example-swiftui/Shared/ExampleViewModel.swift +++ b/example-swiftui/Shared/ExampleViewModel.swift @@ -3,23 +3,11 @@ import SwiftUI import Appwrite import NIO -let host = "https://localhost/v1" -let projectId = "test" - extension ExampleView { - + class ViewModel : ObservableObject { - let client = Client() - .setEndpoint(host) - .setProject(projectId) - - lazy var account = Account(client) - lazy var storage = Storage(client) - lazy var realtime = Realtime(client) - @Published var downloadedImage: Image? = nil - @Published public var username: String = "test@test.test" @Published public var password: String = "password" @Published public var userId: String = "unique()" @@ -29,7 +17,7 @@ extension ExampleView { @Published public var collectionId: String = "test" @Published public var isShowPhotoLibrary = false @Published public var response: String = "" - + func register() async { do { let user = try await account.create( @@ -38,46 +26,77 @@ extension ExampleView { password: password ) self.userId = user.id - self.response = String(describing: user.toMap()) + + DispatchQueue.main.async { + self.response = String(describing: user.toMap()) + } } catch { - self.response = error.localizedDescription + DispatchQueue.main.async { + self.response = error.localizedDescription + } } } - + func login() async { do { let session = try await account.createEmailPasswordSession( email: username, password: password ) - self.response = String(describing: session.toMap()) + + guard let token = UserDefaults.standard.string(forKey: "fcmToken") else { + return + } + + guard let target = try? await account.createPushTarget( + targetId: ID.unique(), + identifier: token + ) else { + return + } + + UserDefaults.standard.set(target.id, forKey: "targetId") + + DispatchQueue.main.async { + self.response = String(describing: session.toMap()) + } } catch { - self.response = error.localizedDescription + DispatchQueue.main.async { + self.response = error.localizedDescription + } } } - + func loginWithFacebook() async { do { _ = try await account.createOAuth2Session(provider: .facebook) - self.response = "Success!" + DispatchQueue.main.async { + self.response = "Success!" + } } catch { - self.response = error.localizedDescription + DispatchQueue.main.async { + self.response = error.localizedDescription + } } } - + func download() async { do { let data = try await storage.getFileDownload( bucketId: bucketId, fileId: fileId ) - self.downloadedImage = Image(data: Data(buffer: data)) + DispatchQueue.main.async { + self.downloadedImage = Image(data: Data(buffer: data)) + } } catch { - self.response = error.localizedDescription + DispatchQueue.main.async { + self.response = error.localizedDescription + } } } - + func upload(image: OSImage) async { #if os(macOS) let fileName = "file.tiff" @@ -86,22 +105,26 @@ extension ExampleView { let fileName = "file.png" let mime = "image/png" #endif - + let file = InputFile.fromData( image.data, filename: fileName, mimeType: mime ) - + do { let file = try await storage.createFile( bucketId: bucketId, fileId: fileId, file: file ) - self.response = String(describing: file.toMap()) + DispatchQueue.main.async { + self.response = String(describing: file.toMap()) + } } catch { - self.response = error.localizedDescription + DispatchQueue.main.async { + self.response = error.localizedDescription + } } } diff --git a/example-swiftui/test (iOS).entitlements b/example-swiftui/test (iOS).entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/example-swiftui/test (iOS).entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/example-swiftui/test (tvOS).entitlements b/example-swiftui/test (tvOS).entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/example-swiftui/test (tvOS).entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/example-swiftui/test (watchOS).entitlements b/example-swiftui/test (watchOS).entitlements new file mode 100644 index 0000000..903def2 --- /dev/null +++ b/example-swiftui/test (watchOS).entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + +