2017년 5월 7일 일요일

Label reads text from .txt file on webserver (kind of Push)


Hello, during improving my application i would like to ask you if there is any possibility of what i want. (I need to say that i am pretty nooby so step by step would be appreciated)

Due to i can not find easy way of push notifications (free) i can imagine, that on screen is 1 label.
This label reads the messages from file "news.txt" on some webserver (www.here.com/news.txt.

This way i could inform users, that they should do the update and stuff. Do you have any idea how this could work? 

--

Follow the following steps:


Step-1: Make sure that you are in the same screen that contains your Label and switch to the Designer View.
Step-2: From under the "Connectivity" menu in the palette, click and drag the "web" component into the viewer.
Step-3: Now switch to the Blocks view.
Step-4: Select your screen_name from the left of the screen. From the options that you'll get, click and drag the "When screen_name.Initialize" block into the designer, where screen_name  is the name of the screen.
Step-5: Now click on the "Web1" or similar named component from the left list. (This is the one that you've recently dragged into the viewer) and select and drag the "set Web1 . Url to" into the designer and make it a "block" with "When screen_name.Initialize component. You can do this by dragging this component into the "When screen_name.Initialize" component, and set the URL to the desired one with a text string.
Step-6: Similarly, select "Web1" once again, and select "call web1.get". This sends the request to the server.
Step-7: Select "Web1" once again and choose "when Web1. GotText" from the menu that appears, and drag it into the  blocks editor. Here we can define what happens when the web component receives (gets) a text as response.
Step-8: In our case, we want to display it as the text for label. So, select that Label item from the left, and select "Set Label1. text to" (this name "Label1" depends on what you've used as a name).
Step-9: Finally, make it a block with "when Web1. GotText"  and to specify its input, hover your cursor over the "responseContent" in the frame of the "when Web1. GotText" until you get a "get responseContent" block. Drag this and make this as the input for "Set Label1. text to" (SEE PICTURE)

and you are done!

Make sure you've set the text of the label to something like "loading news..." initially, so that the time taken during the process can be covered. You have to be connected to the internet when the screen is opened, else you'll get a "1101" Error message.

--

댓글 없음:

댓글 쓰기