SendingNetwork
  • OVERVIEW
    • Getting Started
    • FAQs
  • Network Instructional Articles
    • Basics
      • Introducing the Edge, WatchDog, and Guardian Nodes
      • Overview
      • Messaging Solution
      • Privacy Solution
      • Rich Communication Solution
      • Multi-Platform Solution
      • Decentralized Identity
      • Multiple Chat Modes
      • How It Works
      • Token Utility
      • The Team
    • Key Concepts
      • Decentralized Identity
      • Social Graphs
      • Edge Node
  • SDK Documentation
    • Glossary
    • JavaScript client SDK
      • DID
      • User
      • Message
      • Room
      • Contact
      • Social Graph
    • iOS client SDK
      • Push
      • DID
      • User
      • Message
      • Room
      • Contact
    • Android client SDK
      • User
      • Room
    • Java SDK
      • DID
      • Room
      • Message
    • Node.js SDK
      • DID
      • Room
      • Message
    • Unreal SDK
      • DID
      • User
      • Message
      • Room
    • Unity SDK
      • DID
      • Room
      • Message
    • Website chat widget SDK
      • Customization
      • DID
      • User
      • Room
      • Message
      • Other
    • Bot SDKs
      • Golang Bot SDK
        • DID
        • User
        • Room
        • Message
    • Extensible Message Interface
    • Push Notifications
    • Flutter SDK
      • DID
      • User
      • Message
      • Room
    • PHP SDK
      • DID
      • Room
      • User
    • Developer Key
  • Acquisition Kit
    • Social Boost Development Instructions
  • WatchDog Agent
    • WatchDog Agent Guide
    • WatchDog Agent Deployment Tutorial
      • Linux Deployment Tutorial
    • One-Click Deployment
  • Edge Node
    • Edge Node Deployment Tutorial
    • VPS Setup Guide
      • Google Cloud Platform (GCP)
      • Amazon Web Services (AWS)
      • Contabo
    • Check Node Stats with Auto-Reply Bot in SendingMe App
    • Alpha-3 Testnet FAQs
  • delegation node
    • Delegation Node Deployment Tutorial
  • Private Delegation Node
  • Use Cases
    • Wallet-to-Wallet Messaging
    • Dapp Notifications
    • Identity Verification
    • Gamer Acquisition
    • Cross-platform Trading
Powered by GitBook
On this page
  • Send text message
  • Send image
  • Listen for messages
  1. SDK Documentation
  2. iOS client SDK

Message

Send text message

client?.sendTextMessage(toRoom: room_id, text: message, completion: { response in })

Parameters:

Name
Type
Description
Required

room_id

string

room id

true

message

string

message content string

true

Send image

client?.sendMessage(toRoom: room_id, messageType: .image, content: <#T##[String : Any]#>, completion: { response in
	<#code#>
})

Parameters:

Name
Type
Description
Required

room_id

string

room id

true

content

json

message content string

true

Listen for messages

var session:MXSession?
    func event_dispatcher(){
        self.session?.start{ response in
            guard response.isSuccess else {
                print("sync envnt failed")
                return
            }
            self.session?.listenToEvents(){ event, direction, customObject in
                switch direction {
                case .forwards:
                    // Live/New events come here
                    if  event.eventId != nil{
                        switch event.wireType{
                            // Got an message from other user.
                        case kMXEventTypeStringRoomMessage:
                            let msg = event.content["body"] as! String
                            print("got message: ", msg, " from: ", event.sender!, "at time: ", event.ageLocalTs)
                            // Send a receipt, then the message won't send again.
                            self.client?.sendReadReceipt(toRoom: event.roomId, forEvent: event.eventId){ response in }
                            if event.sender != self.user_id && msg == "ping" {
                                self.client?.sendTextMessage(toRoom:event.roomId, text: "pong"){ response in
                                    switch response{
                                    case .success(let data):
                                        print("response data: ", data)
                                        break
                                    case .failure(let error):
                                        print(error);
                                    }
                                }
                            }
                            break;
                            
                            // Room event.
                        case kMXEventTypeStringRoomMember:
                            let ms = event.content["membership"] as! String
                            if  ms == "invite"{
                                // Invited by a user.
                                print("invited to room: \(event.roomId!) by user: \(event.sender!)")
                                
                            }else if ms == "join"{
                                print("join the room: ", event.roomId)
                            }
                            break;
                        default:
                            print("room event: ", event.roomId, event.eventType, event.type, event.content)
                        }
                    }else{
                        print("room event: ", event)
                    }
                    break
                    
                case .backwards:
                    print("get event backwards: ", event)
                    // Events that occurred in the past will come here when requesting pagination.
                    // roomState contains the state of the room just before this event occurred.
                    break
                }
            }
        }
    }
PreviousUserNextRoom

Last updated 1 year ago