diff --git a/XMTPiOSExample/Podfile.lock b/XMTPiOSExample/Podfile.lock index b0956012..d785d4d6 100644 --- a/XMTPiOSExample/Podfile.lock +++ b/XMTPiOSExample/Podfile.lock @@ -1,3 +1,3 @@ PODFILE CHECKSUM: e82385142d41677b470dd3362d25b239b9c3621c -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 diff --git a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj index 8ff068ce..74471f92 100644 --- a/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj +++ b/XMTPiOSExample/XMTPiOSExample.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ A6C0F3862AC1E549008C6AA7 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6C0F3852AC1E549008C6AA7 /* Data.swift */; }; A6D192D0293A7B97006B49F2 /* ConversationListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D192CF293A7B97006B49F2 /* ConversationListView.swift */; }; A6E774162B154CF000F01DFF /* XMTP in Frameworks */ = {isa = PBXBuildFile; productRef = A6E774152B154CF000F01DFF /* XMTP */; }; + C13CD1CA3A2C3E64BFEA427C /* Pods_XMTPiOSExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 076720F1CA64F2858C4BD14E /* Pods_XMTPiOSExample.framework */; }; + E613B7204F3AB6E0F2D78529 /* Pods_NotificationService.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B3C5E1AFE96305546C0CEA1D /* Pods_NotificationService.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -68,6 +70,11 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 076720F1CA64F2858C4BD14E /* Pods_XMTPiOSExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_XMTPiOSExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3191508CEB23D7A6D616F4E1 /* Pods-XMTPiOSExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.release.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.release.xcconfig"; sourceTree = ""; }; + 3D29AC38BB90CB2A04D2E4D7 /* Pods-XMTPiOSExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-XMTPiOSExample.debug.xcconfig"; path = "Target Support Files/Pods-XMTPiOSExample/Pods-XMTPiOSExample.debug.xcconfig"; sourceTree = ""; }; + 47170F865733F9BD4A7CCF14 /* Pods-NotificationService.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.debug.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.debug.xcconfig"; sourceTree = ""; }; + 6CD71B46527F4C80D1352D67 /* Pods-NotificationService.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationService.release.xcconfig"; path = "Target Support Files/Pods-NotificationService/Pods-NotificationService.release.xcconfig"; sourceTree = ""; }; A60FC8BE293AD054001697E3 /* MessageComposerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerView.swift; sourceTree = ""; }; A60FC8C0293AD171001697E3 /* ConversationDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationDetailView.swift; sourceTree = ""; }; A60FC8C2293AD18A001697E3 /* PreviewClientProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewClientProvider.swift; sourceTree = ""; }; @@ -94,6 +101,7 @@ A6C0F3852AC1E549008C6AA7 /* Data.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; A6D192CF293A7B97006B49F2 /* ConversationListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConversationListView.swift; sourceTree = ""; }; A6E774192B154D1E00F01DFF /* xmtp-ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "xmtp-ios"; path = ..; sourceTree = ""; }; + B3C5E1AFE96305546C0CEA1D /* Pods_NotificationService.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NotificationService.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -110,6 +118,7 @@ A69F33C6292DC992005A5556 /* XMTP in Frameworks */, A6C0F37B2AC1E321008C6AA7 /* Starscream in Frameworks */, A65F070A297B5E8600C3C76E /* KeychainAccess in Frameworks */, + C13CD1CA3A2C3E64BFEA427C /* Pods_XMTPiOSExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -119,12 +128,24 @@ files = ( A6AE5194297B62C8006FDD0F /* KeychainAccess in Frameworks */, A6AE5191297B625F006FDD0F /* XMTP in Frameworks */, + E613B7204F3AB6E0F2D78529 /* Pods_NotificationService.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 07F1F161F3E60D564A26684F /* Pods */ = { + isa = PBXGroup; + children = ( + 47170F865733F9BD4A7CCF14 /* Pods-NotificationService.debug.xcconfig */, + 6CD71B46527F4C80D1352D67 /* Pods-NotificationService.release.xcconfig */, + 3D29AC38BB90CB2A04D2E4D7 /* Pods-XMTPiOSExample.debug.xcconfig */, + 3191508CEB23D7A6D616F4E1 /* Pods-XMTPiOSExample.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; A6281986292DC825004B9117 = { isa = PBXGroup; children = ( @@ -133,6 +154,7 @@ A6AE5181297B61AE006FDD0F /* NotificationService */, A6281990292DC825004B9117 /* Products */, A69F33C4292DC992005A5556 /* Frameworks */, + 07F1F161F3E60D564A26684F /* Pods */, ); sourceTree = ""; }; @@ -183,6 +205,8 @@ A69F33C4292DC992005A5556 /* Frameworks */ = { isa = PBXGroup; children = ( + B3C5E1AFE96305546C0CEA1D /* Pods_NotificationService.framework */, + 076720F1CA64F2858C4BD14E /* Pods_XMTPiOSExample.framework */, ); name = Frameworks; sourceTree = ""; @@ -228,6 +252,7 @@ isa = PBXNativeTarget; buildConfigurationList = A628199E292DC826004B9117 /* Build configuration list for PBXNativeTarget "XMTPiOSExample" */; buildPhases = ( + B508F44B5015A157BE78A7AE /* [CP] Check Pods Manifest.lock */, A628198B292DC825004B9117 /* Sources */, A628198C292DC825004B9117 /* Frameworks */, A628198D292DC825004B9117 /* Resources */, @@ -258,6 +283,7 @@ isa = PBXNativeTarget; buildConfigurationList = A6AE5188297B61AE006FDD0F /* Build configuration list for PBXNativeTarget "NotificationService" */; buildPhases = ( + 9DCEED4B8300ECFB04308A62 /* [CP] Check Pods Manifest.lock */, A6AE517C297B61AE006FDD0F /* Sources */, A6AE517D297B61AE006FDD0F /* Frameworks */, A6AE517E297B61AE006FDD0F /* Resources */, @@ -338,6 +364,53 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 9DCEED4B8300ECFB04308A62 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-NotificationService-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + B508F44B5015A157BE78A7AE /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-XMTPiOSExample-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ A628198B292DC825004B9117 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -495,6 +568,7 @@ }; A628199F292DC826004B9117 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3D29AC38BB90CB2A04D2E4D7 /* Pods-XMTPiOSExample.debug.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -536,6 +610,7 @@ }; A62819A0292DC826004B9117 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3191508CEB23D7A6D616F4E1 /* Pods-XMTPiOSExample.release.xcconfig */; buildSettings = { ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; @@ -576,6 +651,7 @@ }; A6AE5189297B61AE006FDD0F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 47170F865733F9BD4A7CCF14 /* Pods-NotificationService.debug.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; @@ -604,6 +680,7 @@ }; A6AE518A297B61AE006FDD0F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 6CD71B46527F4C80D1352D67 /* Pods-NotificationService.release.xcconfig */; buildSettings = { CODE_SIGN_ENTITLEMENTS = NotificationService/NotificationService.entitlements; CODE_SIGN_STYLE = Automatic; diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata b/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..157b58d4 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/swiftpm/Package.resolved b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..34e5f7f3 --- /dev/null +++ b/XMTPiOSExample/XMTPiOSExample.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,212 @@ +{ + "pins" : [ + { + "identity" : "bigint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/attaswift/BigInt", + "state" : { + "revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6", + "version" : "5.3.0" + } + }, + { + "identity" : "connect-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/bufbuild/connect-swift", + "state" : { + "revision" : "6f5afc57f44a3ed15b9a01381ce73f84d15e43db", + "version" : "0.3.0" + } + }, + { + "identity" : "cryptoswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "state" : { + "revision" : "039f56c5d7960f277087a0be51f5eb04ed0ec073", + "version" : "1.5.1" + } + }, + { + "identity" : "generic-json-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/iwill/generic-json-swift", + "state" : { + "revision" : "0a06575f4038b504e78ac330913d920f1630f510", + "version" : "2.0.2" + } + }, + { + "identity" : "gzipswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/1024jp/GzipSwift", + "state" : { + "revision" : "7a7f17761c76a932662ab77028a4329f67d645a4", + "version" : "5.2.0" + } + }, + { + "identity" : "keychainaccess", + "kind" : "remoteSourceControl", + "location" : "https://github.com/kishikawakatsumi/KeychainAccess", + "state" : { + "branch" : "master", + "revision" : "e0c7eebc5a4465a3c4680764f26b7a61f567cdaf" + } + }, + { + "identity" : "secp256k1.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/GigaBitcoin/secp256k1.swift.git", + "state" : { + "revision" : "48fb20fce4ca3aad89180448a127d5bc16f0e44c", + "version" : "0.10.0" + } + }, + { + "identity" : "swift-atomics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-atomics.git", + "state" : { + "revision" : "cd142fd2f64be2100422d658e7411e39489da985", + "version" : "1.2.0" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "a902f1823a7ff3c9ab2fba0f992396b948eda307", + "version" : "1.0.5" + } + }, + { + "identity" : "swift-docc-plugin", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-plugin.git", + "state" : { + "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", + "version" : "1.3.0" + } + }, + { + "identity" : "swift-docc-symbolkit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-docc-symbolkit", + "state" : { + "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-http-types", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-http-types", + "state" : { + "revision" : "99d066e29effa8845e4761dd3f2f831edfdf8925", + "version" : "1.0.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", + "version" : "1.5.3" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c", + "version" : "2.62.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "798c962495593a23fdea0c0c63fd55571d8dff51", + "version" : "1.20.0" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "3bd9004b9d685ed6b629760fc84903e48efec806", + "version" : "1.29.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9", + "version" : "2.25.0" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e", + "version" : "1.20.0" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "07f7f26ded8df9645c072f220378879c4642e063", + "version" : "1.25.1" + } + }, + { + "identity" : "walletconnectswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/WalletConnect/WalletConnectSwift", + "state" : { + "branch" : "master", + "revision" : "9e4dfba34fb35336fd5da551285d7986ff536cb8" + } + }, + { + "identity" : "web3.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/argentlabs/web3.swift", + "state" : { + "revision" : "8ca33e700ed8de6137a0e1471017aa3b3c8de0db", + "version" : "1.6.0" + } + }, + { + "identity" : "websocket-kit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/vapor/websocket-kit.git", + "state" : { + "revision" : "53fe0639a98903858d0196b699720decb42aee7b", + "version" : "2.14.0" + } + }, + { + "identity" : "xmtp-rust-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/xmtp/xmtp-rust-swift", + "state" : { + "branch" : "main", + "revision" : "eb931c2f467c2a71a621f54d7ae22887b234c13a" + } + } + ], + "version" : 2 +} diff --git a/XMTPiOSExample/XMTPiOSExample/ContentView.swift b/XMTPiOSExample/XMTPiOSExample/ContentView.swift index 1b80321a..39fbb9a1 100644 --- a/XMTPiOSExample/XMTPiOSExample/ContentView.swift +++ b/XMTPiOSExample/XMTPiOSExample/ContentView.swift @@ -19,7 +19,6 @@ struct ContentView: View { @State private var isShowingQRCode = false @State private var qrCodeImage: UIImage? - @State private var isConnectingWallet = false @State private var client: Client? @@ -27,21 +26,9 @@ struct ContentView: View { VStack { switch status { case .unknown: - Button("Connect Wallet") { isConnectingWallet = true } - .sheet(isPresented: $isConnectingWallet) { - LoginView(onConnected: { client in - do { - let keysData = try client.privateKeyBundle.serializedData() - Persistence().saveKeys(keysData) - self.status = .connected(client) - } catch { - print("Error setting up client: \(error)") - } - - print("Got a client: \(client)") - }) - } - Button("Generate Wallet") { generateWallet() } + Button("Connect Wallet", action: connectWallet) + Button("Generate Wallet", action: generateWallet) + Button("Wallet from Key", action: generateWalletWithPrivateKeys) case .connecting: ProgressView("Connecting…") case let .connected(client): @@ -66,12 +53,112 @@ struct ContentView: View { } } + func connectWallet() { + status = .connecting + + do { + switch try accountManager.account.preferredConnectionMethod() { + case let .qrCode(image): + qrCodeImage = image + + DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { + self.isShowingQRCode = true + } + case let .redirect(url): + UIApplication.shared.open(url) + case let .manual(url): + print("Open \(url) in mobile safari") + } + + Task { + do { + try await accountManager.account.connect() + + for _ in 0 ... 30 { + if accountManager.account.isConnected { + var options = ClientOptions() + options.api.env = .production + options.api.isSecure = true + let client = try await Client.create(account: accountManager.account, options: options) + + let keysData = try client.privateKeyBundle.serializedData() + Persistence().saveKeys(keysData) + + self.status = .connected(client) + self.isShowingQRCode = false + return + } + + try await Task.sleep(for: .seconds(1)) + } + + self.status = .error("Timed out waiting to connect (30 seconds)") + } catch { + await MainActor.run { + self.status = .error("Error connecting: \(error)") + self.isShowingQRCode = false + } + } + } + } catch { + status = .error("No acceptable connection methods found \(error)") + } + } + func dataFromHexString(_ hex: String) -> Data? { + var data = Data(capacity: hex.count / 2) + var buffer = 0 + var index = 0 + for char in hex { + if let value = char.hexDigitValue { + if index % 2 == 0 { + buffer = value << 4 + } else { + buffer |= value + data.append(UInt8(buffer)) + } + index += 1 + } else { + return nil + } + } + return data + } + func generateWalletWithPrivateKeys() { + Task { + do { + let privateKeyString = "private_key" // Your PrivateKey instance here + // Function to convert hex string to Data + + + if let privateKeyData = dataFromHexString(privateKeyString) { + let privateKey = try PrivateKey(privateKeyData) + let client = try await Client.create(account: privateKey, options: ClientOptions(api: .init(env: .production))) + + + print(client.address) + let keysData = try client.privateKeyBundle.serializedData() + Persistence().saveKeys(keysData) + + await MainActor.run { + self.status = .connected(client) + } + } else { + // Handle the error case where the hex string couldn't be converted to Data + } + + + } catch { + await MainActor.run { + self.status = .error("Error generating wallet: \(error)") + } + } + } + } func generateWallet() { Task { do { let wallet = try PrivateKey.generate() let client = try await Client.create(account: wallet, options: .init(api: .init(env: .dev, isSecure: true, appVersion: "XMTPTest/v1.0.0"))) - let keysData = try client.privateKeyBundle.serializedData() Persistence().saveKeys(keysData) diff --git a/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift b/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift index 123fd2bc..f0cdf15f 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/ConversationDetailView.swift @@ -11,8 +11,25 @@ import XMTP struct ConversationDetailView: View { var client: XMTP.Client var conversation: XMTP.Conversation + @State private var streamTask: Task<(), Error>? = nil @State private var messages: [DecodedMessage] = [] + + func startStream() { + streamTask = Task { + do { + for try await message in conversation.streamMessages() { + let content: String = try message.content() + print("Received message: \(content)") + await MainActor.run { + messages.append(message) + } + } + } catch { + print("Error in message stream: \(error)") + } + } + } var body: some View { VStack { @@ -22,16 +39,15 @@ struct ConversationDetailView: View { } .task { await loadMessages() + startStream() } - .task { - do { - for try await message in conversation.streamMessages() { - await MainActor.run { - messages.append(message) - } - } - } catch { - print("Error in message stream: \(error)") + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in + streamTask?.cancel() + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in + Task{ + await loadMessages() + startStream() } } diff --git a/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift b/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift index f92c2465..d8162668 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/ConversationListView.swift @@ -37,7 +37,7 @@ struct ConversationListView: View { do { for try await conversation in await client.conversations.stream() { conversations.insert(conversation, at: 0) - + print("Received conversation: \(conversation.peerAddress)") await add(conversations: [conversation]) } diff --git a/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift b/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift index 75dda939..44e3a089 100644 --- a/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift +++ b/XMTPiOSExample/XMTPiOSExample/XMTPiOSExampleApp.swift @@ -9,13 +9,15 @@ import SwiftUI import XMTP class AppDelegate: NSObject, UIApplicationDelegate { + func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { + + print("Application did finish launching") // Add this line // Change this to the URL of where your https://github.com/xmtp/example-notification-server-go is hosted XMTPPush.shared.setPushServer("YOUR PUSH SERVER HERE") - + return true } - func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { Task { do {