My goal is to create an app that sends the number "1" to a webserver which records the number inside a text file hosted there. I'm very new to apps, php, asihttprequest, etc. Research has suggested using the asihttprequest wrapper for its simplicity. I set up a webpage recently using iPower which I would like to communicate with. I have created an app with a button, when pressed activates the following code:
I need help writing a php file that will communicate with the above code and write to a text file. I've been trying to deduce how to make this work from others' broken apps, example code, and thread questions, but it's hard troubleshooting problems with my limited knowledge. I would greatly appreciate if anyone could recommend a tutorial on how to achieve my goal. In addition, I have the following questions:
1. Do the code request setPostValue:@"Ben Copsey" forKey:@"name" send the string in quotations as data to the server?
2. What does "forkey" mean?
3. I asked iPower if I need to change the permissions on my php and text files. The said they are currently set to the default of 644. I'm not sure what this entails. Should this exercise be as simple as uploading the php and text files to the parent directory (http://www.mywebpage.com/write.php) without checking permissions?
1. Do the code request :setPostValue@"Ben Copsey" forKey:@"name" send the string in quotations as data to the server?
2. What does "forkey" mean?
3. I asked iPower if I need to change the permissions on my php and text files. The said they are currently set to the default of 644. I'm not sure what this entails. Should this exercise be as simple as uploading the php and text files to the parent directory (create a free web site at mywebpage.com) without checking permissions?
I appreciate any help on my project.
Andrew
1) yes, that code prepare the data that will be sent.
2) "for Key", mean that you are storing "Ben Copsey" in a key: "name" (the same concept that use NSDictionary)
3) no, you no need to change anything
for your purpose, 644 mean: permission 6 for User, permission 4 for Group and permission 4 for Other (User\Group\Other are the unix classes for account)
permission 6 = 110 in binary, so 1= Read 1=Write 0=execute for user,
permission 4 = 100 in binary, so 1= Read for group,
permission 4 = 100 in binary, so 1 = Read for other,
1) yes, that code prepare the data that will be sent.
2) "for Key", mean that you are storing "Ben Copsey" in a key: "name" (the same concept that use NSDictionary)
3) no, you no need to change anything
for your purpose, 644 mean: permission 6 for User, permission 4 for Group and permission 4 for Other (User\Group\Other are the unix classes for account)
permission 6 = 110 in binary, so 1= Read 1=Write 0=execute for user,
permission 4 = 100 in binary, so 1= Read for group,
permission 4 = 100 in binary, so 1 = Read for other,
and this is the default permissions.
Thank you both for your help. I got my app running and successfully posted data to my website through the app simulator.
What does this mean, [request setDelegate:self];?
Also, how do I make the server echo back a response to confirm successful data transfer?
Last edited by Runner1985; 12-18-2010 at 08:01 AM.
Basically delegate is an object that has been assigned as a delegate of another object, and the delegate basically have the task to receive some "events" from the object.
In this case assuming that you are writing on CustomViewController, then you will have something like
CustomViewController.m:
Code:
-(void)myDownloadMethod{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self]; //We are on CustomViewController.m, so self represent the current istance of CustomViewController!
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[request startAsynchronous];
}
- (void)requestDone:(ASIHTTPRequest *)request
{
NSString *response = [request responseString];
}
- (void)requestWentWrong:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}
You are setting the delegate for object request, that delegate is "self" self is a special variable that return a pointer to "the current class"
Why we use Delegate? because the object "request", will call method like
that methods (requestDone, requestWentWrong) will be called just on delegate (so in this case you write these methods on CustomViewController.m), if you no set the delegate, that metods will be not called and you aren't able to retrieve the response from server.
Quote:
Originally Posted by Runner1985
Also, how do I make the server echo back a response to confirm successful data transfer?
in the php script you can add (as last line is fine)
how do i create this server side to receive files that my iPhone sends? im also a rookie in php or any kinds of server... plz lend me a hand and i reeeeeeeeeeeeeeealy appreciate that!