Search code examples
phpiphonemysqlasihttprequest

ASIHTTPRequest help with setup on iPhone SDK?


I have created a new project in Xcode and performed the following to add ASIHTTPRequest:

  • Copied these files into the main project folder

    • ASIHTTPRequestConfig.h
    • ASIHTTPRequestDelegate.h
    • ASIProgressDelegate.h
    • ASICacheDelegate.h
    • ASIHTTPRequest.h
    • ASIHTTPRequest.m
    • ASIDataCompressor.h
    • ASIDataCompressor.m
    • ASIDataDecompressor.h
    • ASIDataDecompressor.m
    • ASIFormDataRequest.h
    • ASIInputStream.h
    • ASIInputStream.m
    • ASIFormDataRequest.m
    • ASINetworkQueue.h
    • ASINetworkQueue.m
    • ASIDownloadCache.h
    • ASIDownloadCache.m
    • ASIAuthenticationDialog.h
    • ASIAuthenticationDialog.m
    • Reachability.h (in the External/Reachability folder)
    • Reachability.m (in the External/Reachability folder)
  • I have then dragged those files onto the right side of the project window

  • I then go, Project -> Edit Active Target, click the + button, and [problem 1] "CFNetwork.framework"" is not there?

I now want to add a new view controller and make the following code work;

NSURL *url = [NSURL URLWithString:[[NSString stringWithFormat:@"http://www.mywebsite.com/script.php?first_name=%@",first_name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request startSynchronous];
NSError *error = [request error];
NSString *response = nil;
if (!error) {

    response = [request responseString];

    NSLog(@"%@",response);

} else {

    return NO;

}
  • I add a new UIViewController Subclass file
  • I insert the code as above and [problem 2] it says that 'first_name' is undefined and a bunch of other errors.

How can I go about resolving both issues? And is there anything I am doing wrong which will hinder this from working as I expect? (Posting a variable to a PHP file, using a textfield and submit button)

Thanks!


Solution

  • I assume you are using Xcode4.

    Click Project in project navigator. Project -> Select Target -> Select Build phases -> Expand Link Binary with Libraries -> Click +. You will find the framework.

    And you have not declared the variable first_name.