Closed riverbaymark closed 2 years ago
hi @riverbaymark im not seeing you calling sendMessage api, did you miss that?
Sorry I left that code out int the above snippet. I call it from my SwiftUi view like below:
func sendData() { print(agoraChatOO.channel) agoraChatOO.channel?.send(AgoraRtmMessage(text: dataTextSending)){message in print(message) } }
agoraChatOO is the @StateObject view model for the AgoraObservable class.
@riverbaymark is there any chance you can provide the minimal reproducible project to me? it seems agoraChat00.channel? can potentially be nil? either you can put everything together or you may provide the reproducible project can help me solve your problem quicker.
Here is a shortened example of my view that utilizes the observable object above. I do check with the print statement in the sendData() function and the agoraChatOO.channel is not nil and is the same as when created in the observable object class.
import SwiftUI
import AgoraRtmKit
struct AgoraChatView: View {
@StateObject var agoraChatOO = AgoraObservable()
@State var dataTextSending: String = ""
@State var joinedChannel: Bool = false
func sendData() {
print(agoraChatOO.channel)
agoraChatOO.channel?.send(AgoraRtmMessage(text: dataTextSending)){message in
print(message)
}
}
var body: some View {
GeometryReader {
geometry in
VStack{
Button(action: {
joinedChannel.toggle()
if !joinedChannel {
self.agoraChatOO.members.removeAll()
self.agoraChatOO.rtckit.leaveChannel()
self.agoraChatOO.rtmkit?.logout()
self.agoraChatOO.rtmIsLoggedIn = false
} else {
self.agoraChatOO.joinChannel()
}
}, label: {
Text("\(joinedChannel ? "Leave" : "Join") Channel")
.accentColor(joinedChannel ? .red : .blue)
})
HStack {
TextField("Message", text: $dataTextSending)
.padding()
.textFieldStyle(RoundedBorderTextFieldStyle())
Spacer()
Button(action: {
self.sendData()
dataTextSending = ""
}) {
Text("Send")
.padding(8)
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(8)
}
}.navigationBarTitle("RadChat")
}
}
}
}
struct AgoraChatView_Previews: PreviewProvider {
static var previews: some View {
AgoraChatView(agoraChatOO: AgoraObservable())
}
}
@riverbaymark can you listen to the connectionStateChange callback and see what you get for both users?
@riverbaymark are the two users logging in with the same rtmId of "test"? They cannot both be the same value.
I usually use UIDevice.current.identifierForVendor?.uuidString
. Note that it will be extremely unlikely to be nil
, but add a fallback random UUID just in case.
I think this issue was solved by changing the RTM ID.
Greetings,
I ran this app demo and no members were showing up in the list after signing on. I took the code and modified it a bit for my own app for messaging and I can successful log into the rtm service and get a successful error response (code 0) when sending a message. The issue is the delegate is not called for either item. I am using the latest RTM version 1.4.10. Below is a sample of my code :
Any help would be greatly appreciated!