Part one - Send and recive SMS
In this tutorial we will use the SMS View in the Ikivo IDE to simulate the sending and receiving of a message.
If you already have a project opened, you can use this one. If not, begin with open a project (File -> New Project)
• Create a new SVG Tiny File in the Ikivo IDE (File -> New…)
• Replace “Add your SVG code here” with the following code:
Waiting for SMS...
• Debug your file and watch the result in the “Playback View” (The only thing visible should be the text string “Waiting for SMS”)
• Add the following javascript code:
The code above contains a script tag. The first part contains the needed variable declarations and statements. The script tag also contains a function; SMSReceived. The first part of the function sets variables by getting information from the SMS View. The simulated SMS sent from the SMS View prints out a log, based on the variables, in the Console View.
In the script, we are using a function called addEventListenerNS. If you want to know more about it and how to use it, click here.
• Debug your file, type in your information in the SMS View, press send and watch the result in the Playback View and the Console View.
Part two - Adding graphics
You have already managed to send a message though the SMS View and watched the result in the Console View. Now we are going to take it a step further and make the message appear in the Playback View.
• Let’s begin with changing our text in the Playback View to something more graphical appealing.
Change:
Waiting for SMS...
To:
Waiting for SMS
From:
To:
Text:
• Debug or run the file, you will se the new graphics in the Playback view.

Now we have the structure, but we want our input from the SMS View to appear in the Playback View instead of in the Console View. To do this, we need to change our script.
• Replace your function SMSReceived with the following function:
function SMSReceived(evt){
//Get the corresponding svgtext elements
var fromText = document.getElementById("fromText");
var toText = document.getElementById("toText");
var messageText = document.getElementById("messageText");
var status = document.getElementById("status");
status.textContent = "SMS received";
// Get the message object
var msg = evt.getMessage();
// Get the first Contact Card from the 'to' list
var toCard = msg.to.getItem(0);
// Get the 'from' Contact Card
var fromCard = msg.from;
// Set the text on the SVG text elements
fromText.textContent = fromCard.name.substring(0,15);
toText.textContent = toCard.name.substring(0,15);
messageText.textContent = msg.getText().substring(0,15);
}
Debug the file. If everything works correctly, your information should appear in the Playback View and no longer be visible in the Console View.


|