[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
[coco8] ScanApp and U8 - English.scc
Hi! how are you? today we want to take a look
to a new feature
added to coco8 that is really cool
called ScanApp. ScannApp is
a very simple application included in coco8
allowing us, accesing the camera phone,
to scan QR codes
and use the content
to perform several activities.
let me show some examples. First,
I will scan a prepared image
for this case,
whose content will determine the opening
of a message box
saying #testOK. We open
ScanApp pointing to the image,
the phone quickly opens a message box
saying #testOK. In a second case
I will scan another image whose content
open the phone browser at
U8 web site.
As you can realize
ScanApp has multiples
usages, but today we want to talk
about, in my opinion,
is the most interesting feature
that allows us to share our
applications or frameworks among
coco8 users in a easy, agile and
modern way. As an example
I will show you a super easy and minimal app
designed as a demo.
It is an application asking for
integer numbers, testing for primality
(prime or composite) condition. Right now, the app
is not installed on my phone. I wrote it,
and uploaded to U8 site
as a contribution. U8 site provides
the QR code image, so when
coco8 user scan the QR
with ScanApp, it will be
installed on the phone
Check this out. I point it, it is installed
and then executed.
Here we can try it, we write any
in the same moment
the app reports
if typed number is prime
Note that during scanning phase, the app
was found among contributions
in U8 site. It was downloaded
and executed. Right now the app is
in my phone and can be found
inside "Smalltalk run" icon.
The app was downloaded and it remains
in the phone as a part of coco8.
This is very interesting because it transforms
U8 site in a kind of store of
contributions where we can upload
our apps or frameworks and any
coco8 user can download it
simply pointing to the
QR code with ScanApp.
As you can see U8 provides the QR code
for each contribution. Now we will do a minimal
walkthrough on how to write
the demo sample app and how to publish it
as a contribution.
In this case the app
is a very simple to write.
Lets take a look
at the code.
The main class of our
app is PrimeViewController
a subclass of UIViewController
for those unfamiliar
with iOS programming, lets say
that UIViewController is a
MVC controller that works also
as a ViewManager. Lets see two
or three interesting methods in this class.
The first one is #viewDidLoad. This method is invoked
when view is recently loaded
so there, it is a good place
to define widgets and layouts
We can see the
an integer number. A text field definition
where we will type the integer number.
Another label for
showing the result of primality tests.
In other words, where it will be showed
the message saying
prime or composite.
In this method it is configured every widget.
Lets see the more important details
on configuring the text field.
Here an important property used
In this case setting type 4
means this field will present
a numeric keyboard. It means
every time user touch
this text field
a numeric keyboard appears
avoiding the case
user inputs non numeric text
and eventualy have to handle
the suitable exceptions.
Another important detail
on configuration is that here
we are linking to
#editingChanged event the #inputTextoChanged: action.
What means that? It means
every time text field change,
by user input o delete action,
any character or number
it will be sent
So lets see the #inputTextChanged:
as we said, the method is activated every time
the text field content is modified
here, as you can see,
the input is tested for primality.
The typed text is converted
to number and then
#testPrimality: method is invoked
asking to number is prime,
according to response the label
shows the word prime or
composite. Here a couple
of lines worth showing.
Here, for example, I add
#isPrime method to Number class returning true or false
depending on receiver
is a prime number or not.
Here we can see two methods
providing diferent ways
of executing the app
once installed in coco8.
And these final lines
tells coco8 to execute the app
once is loaded
from U8 contribution.
Ok, that's all for coding issues.
Now we have to do
the build to compile S8 code
The last step is
upload the contribution to U8 site, lets see how.
We have to be logued in U8 site.
Go to Start Coding and click the cross,
the plus sign (+), do not click the button
so a menu it will be displayed
with several options to init a contribution
in this case
we choose iOSApp. This option
creates a contribution
forking a base
template for our
Here we click in edit
so we can change the title
select an image
representing the app and then upload
the files of our contribution
It is impotant to say
that ScanApp will not accepts arbitrary
uploaded files. It will accept
files with names like index.app.st
or index.app.js or
we have to upload something with any of
these names. If we upload a st file, a
on the device. If we upload a js file
it will be accepted as a compiled code.
In order to names conform to the rule
we can prepare the script build
to generetate the output
with names conforming the rule, or once
generated js file, as in my case
it generated prime.st.js,
I renamed to index.app.st.js
In order to upload it
as a contribution so
that ScanApp finds it and run it
here we can see U8
generated the QR code image
so it is all done, now is a matter of
save the contribution, publish it
and spread it.
Well, that is all for today
any questions do not hesitate
to consult through smalltalking list
thanks and see you later.