Creating StreamChat Channel SwiftUI

270 views Asked by At

I have a swiftui app and trying to integrate the Stream Chat SDK. I have been able to successfully log a user in, but having difficulty creating a channel and the documentation is quite challenging to work with to understand the issue. Here is my code to create a hardcoded "general" channel:

class ChatManager: ObservableObject {

// vars and other methods

    public func createNewChannel(name: String) {
        
        do {
            let channelId = ChannelId(type: .messaging, id: "general")
            let channelController = try chatClient.channelController(
                createChannelWithId: channelId,
                name: name,
                members: [],
                isCurrentUserMember: true
            )
            channelController.synchronize { error in
                if let error = error {
                    print(error)
                }
            }
            
        } catch {
            print(error)
        }
    
    } 
}

The usage of this function is just a button that triggers it.

Here is my ChannelListView:

struct ChannelListView: View {
    @EnvironmentObject var chatManager: ChatManager
    
    var body: some View {
        ChatChannelListView(
            viewFactory: CustomFactory.shared,
            channelListController: chatManager.customChannelListController
        )
    }
}

class CustomFactory: ViewFactory {

    @Injected(\.chatClient) public var chatClient

    private init() {}

    public static let shared = CustomFactory()

    func makeNoChannelsView() -> some View {
        VStack {
            Text("This is our own custom no channels view.")
        }
    }

}

The error code get's printed repeatedly after I tap the button. Here is the error code I'm getting:

2023-08-31 09:28:09.799 [ERROR] [com.apple.root.default-qos] [APIClient.swift:223] [executeRequest(endpoint:completion:)] > Error WaiterTimeout in /Users/username/Library/Developer/Xcode/DerivedData/project_name/SourcePackages/checkouts/stream-chat-swift/Sources/StreamChat/Utils/Timers.swift:54

Thanks for your help!

2

There are 2 answers

1
Martin Mitrevski On

Are you still having the issue? Additionally, it would be great to know which SDK version you are using.

From what I've understood, the connect method finishes without errors, but you can't create a channel. Based on the sample you provided, one thing I've noticed is that you are only keeping the chatController in the local scope of the function, it will probably get deallocated before the completion is called. Can you try by making it an instance variable instead?

Also, for faster responses from our team, I would recommend using our support: https://getstream.io/contact/support/.

0
Mr.SwiftOak On

What helped solving the issue was using Cocoapods instead of Swift Package Manager I also needed to set up ENABLE_USER_SCRIPT_SANDBOXING to 'No' according to following SO answer

enter image description here