How To Receive Data From The Server In iPhone

In this application we will see how to receive data from the server. This is the simple login application and when you login in the screen it will display the message, whatever we set in the server page. So let see how it will be worked.

Step 1: Create a View base application using template. Give the application name “SendReceiveData”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the SendReceiveDataViewController class for you. Expand Resources and notice the template generated a separate nib, SendReceiveDatayViewController.xib, for the “SendReceiveData”.

Step 4: In the SendReceiveDataViewController.h file, we have added UITextField, UILabel, and one buttonClick method. So make the following changes in the file.

 

 

 

Step 5: Double click the SendReceiveDataViewController.xib file and open it to the Interface Builder. Drag three labels, one Round Rect Button and two TextField from the library and place it to the view window(See the figure below). Connect File’s Owner icon to the view icon and select view and drag File’s Owner icon to the “Input Your Values” and select greeting . Next drag File’s Owner icon to the first text field and select nameInput,do the same thing for the next text field and select passInput. Select the login button and bring up Connection Inspector and drag TouchUpInside to the File’s Owner icon and select buttonClick: action. Now save the SendReceiveDataViewController.xib file, close it and go back to the Xcode.

Step 6: Open the SendReceiveDataViewController.m file and make the following changes in the file:

 

 

 

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here SendReceiveData-1

Leave a Comment:

18 comments
Pascal says June 15, 2010

Hello,

what would be the code for a “cancel” button? How can I close the pending connection before it is completed? Thanks.

Pascal

Reply
Pascal says June 15, 2010

Hello,

what would be the code for a "cancel" button? How can I close the pending connection before it is completed? Thanks.

Pascal

Reply
mapega says June 19, 2010

Can you tell me a correct login and password for test, please?

Reply
Sushant says June 19, 2010

In our application, we are not set username and password, when user input username and password and click it then invalid message display in the screen that message comes from the server.

Reply
mapega says June 19, 2010

Thanks for your answer. Is possible to download chckusr.php. It should be great to understand completly. Thanks in advance.

If you can’t by this way, may be you can send me the file by e-mail…

Reply
mapega says June 19, 2010

Ok, I create my own php and it works perfect. Thanks for your post, It help me a lot. Thanks 🙂

Reply
davidv says June 22, 2010

What is the function that PHP uses to return the message back to the app…
I am using ColdFusion.

Reply
Tony says July 6, 2010

all you have to do on the server side is read the posted vars uname and pwd and then echo something. I did a quick if statement like this…

This is my first app, so I don’t know how to send back specific data in vars like you would in AS3 or something like that… this is just reading the string on the page. This looks like a basic idea of how to get information to and from a web server. From there you can use the web server to manipulate your inputs and retrieve data. The possibilities are endless…. I love this stuff!

Reply
Tony says July 6, 2010

all you have to do on the server side is read the posted vars uname and pwd and then echo something. I did a quick if statement like this…

<php?
$user = $_POST[‘uname’];

if ($user == ‘tony’)
{
echo "You are the coolest guy I know";
}else{
echo "You suck"
}
?>

This is my first app, so I don’t know how to send back specific data in vars like you would in AS3 or something like that… this is just reading the string on the page. This looks like a basic idea of how to get information to and from a web server. From there you can use the web server to manipulate your inputs and retrieve data. The possibilities are endless…. I love this stuff!

Reply
Abi says July 24, 2010

Thanks for this apps

Reply
arpan says August 4, 2010

will u plz send the chckusr.php source codes…

Reply
Dipak Patil says January 6, 2011

please,
give one example on socket programming in iphone,
how can we send message from client(iphone) to server.
give one demo app. please.

Reply
casper says January 27, 2011

if i want it for GET .. what should i do? ..

i am using it to login on website .. but the thing is that i m getting an error msg which is invalid username and password .. :S

Reply
spatil says December 8, 2011

Hi ,

Thanks for this tutorial..
But can you please post tutorial for retrieve data from php

Reply
Dmitri says June 20, 2012

Thank you so so much for this tutorial! 😀

Reply
RickyRan says June 27, 2012

All I am getting is (null) as the output, is the server still up?

Reply
response from website is not coming properly | Code and Programming says December 31, 2012

[…] am newbie for iPhone application. I have followed this tutorial for login from […]

Reply
how to go to another ViewController after successful login | Code and Programming says December 31, 2012

[…] am newbie for iPhone application. I have followed this tutorial for login from […]

Reply
Add Your Reply