twilio / twilio-conversations-demo-ios-swift

Twilio Conversations for iOS Demo application in Swift
MIT License
17 stars 18 forks source link

Message from cross platform not received in iOS #1

Closed NadeemIqbal closed 2 years ago

NadeemIqbal commented 2 years ago

Message is sending and receiving on iOS to iOS devices. but not receiving any messages on iOS from any other platform like Android and Web(React).

berkus commented 2 years ago

Hi, did you verify the message was actually sent?

The only reason I can think for this happening is that the network is not available and the app is just offline.

Gray-Wind commented 2 years ago

It could be also a difference between tokens used in other applications and iOS one.

whoisarte commented 2 years ago

Hi, I have this problem too. But, in conversationsList view, there are the number of messages received from other users in the conversation increase, but in the conversation view doesn't show that messages. It is just a problem to show the messages

whoisarte commented 2 years ago

Hi, I catched up what's the problem (partially) when I received messages from not iOS devices. Is in ConversationsDataConverter file. The "guard let" sentence that tries to catch uuid value always came nil from web and android devices (using other demo projects), when it tries to parse the following sentence: "message.attributes()?.toStringBasedDictionary()["uuid"] as? String". Then, because it is empty, the flow enters to the "else" block in the guard let, and makes a nil return.

I solve it by making a new UUID with UUID() constructor, to generate a random identifier when it comes nil or when it fails to parse. I still think this is not the best solution but partially it works nice. (I'll make test with this to see if other things are not affected).


func convert(message: TCHMessage) -> MessageDataItem? {
        var uuid = ""
        if let uuidFromMessage = message.attributes()?.toStringBasedDictionary()["uuid"] as? String {
            uuid = uuidFromMessage
            print("UUID from iOS Device -> \(uuid)")
        } else {
            print("UUID not catched (making random one...)")
        }
        guard let messageSid = message.sid else { return nil }
        return MessageDataItem(sid: messageSid,
                               uuid: uuid.isEmpty || uuid == "" ? UUID().uuidString : uuid,
                               index: message.index as! UInt,
                               direction: MessageDirection.outgoing,
                               author: message.author ?? "",
                               body: message.body ?? "",
                               dateCreated: message.dateCreatedAsDate?.timeIntervalSince1970 ?? 0,
                               sendStatus: MessageSendStatus.undefined,
                               conversationSid: "",
                               type: message.messageType,
                               mediaSid: message.mediaSid,
                               reactions: MessageReactionsModel.fromAttributes(jsonAttributes: message.attributes()),
                               mediaStatus: .none
                            )
    }