Showing posts with label Objective C. Show all posts
Showing posts with label Objective C. Show all posts

Tuesday, August 12, 2014

Download a password protected webpage with Objective C for iOS/iPhone/iPad

1) Go to http://allseeing-i.com/ASIHTTPRequest and download the latest version (the .tar tarball file)

2) In Xcode, in your project, click on the file folder icon, which is the top left button, so that you can see all the .h and .m files in your project.
3) Open the .tar file in Finder, and drag-and-drop the Classes/ASI* files to Xcode, on the left hand side, in the same directory that the rest of your .h and .m files are.  NOTE: Don't copy the files manually through the command line (Terminal) nor outside of Xcode.
4) If you are creating an iPhone app, drag-and-drop the External/Reachability/Reachability* files to Xcode, on the left hand side, in that same directory.
5) Go to http://allseeing-i.com/ASIHTTPRequest/Setup-instructions and follow the step 2 directions, which is setting up the Build Phases.
6) If you are using ARC, then you need to disable ARC for the ASI* and Reachability* files.  Click on your main project on the left hand side, then choose "Build Phases", and expand the "Compile Sources" section.  For all of the ASI* and Reachability.m files, add in the following flag for "Compiler Flags": -fno-objc-arc (Also see http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project)
7) At the top of your .m file where you want to download the webpage, paste the following line:
#import "ASIHTTPRequest.h"

8) In that same .m file, download the file by doing this:


    NSString* url = @"http://www.google.com";
    NSURL *nsurl = [NSURL URLWithString:url];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:nsurl];
    [request setUsername:@"enterUsernameHere"];
    [request setPassword:@"enterPasswordHere"];
    
    [request startSynchronous];
    NSError *error = [request error];
    if (!error) {
        NSString *response = [request responseString];
        NSLog(response);
    }

That's it!

Sunday, August 10, 2014

How to retrieve a Text Field value in iOS/iPad/iPhone programming in Xcode

1) Drag the Text Field onto your storyboard

2) On the top right side of the screen, you'll see a button that looks like a tux with a bow tie.  It is labeled "Show the Assistant Editor".  Click on that button

3) You should see the storyboard side-by-side to a text window showing code.  Make sure that the .h is showing, such as ViewController.h - you can switch the file by clicking on "Automatic".

4) Scroll the text edit window down to the end, right before "@end".

5) Hold down control, and drag the Text Field to the ViewController.h text edit windows, and drop it right before the "@end".  Type in any name for the Text Field, such as textEntryField.

6) In the callback function (not necessarily a callback function for the Text Field) in the ViewController.m file, you can retrieve the value of the Text Field through "_textEntryField.text".  For example:


NSString* entryText = _textEntryField.text;
NSLog(@"The text in the Text Field is: %@", entryText);

Create callback to respond to button click in iOS with Xcode

1) Click on the storyboard that has the Button that you want to respond to.

2) Near the top right corner, you'll see a button that looks like a tux with a bow tie, entitled "Show the Assistant Editor".  Click on that.

3) Make sure that the .m file is showing (e.g. ViewController.m)

4) Hold down control and drag the button from the storyboard down to the text editor which will create a new function.  Type in a name for the function, such as "buttonTapped".

5) Click "Connect".

6) Now, fill in the callback function.

Friday, September 14, 2012

cannot find ... NXConstantString

Why do I get the following error (on Linux using GNUstep), when trying to compile an Objective C program?

... error: cannot find interface declaration for ‘NXConstantString’ ..

Answer:

Use the following flag when compiling everything (.o's, main, etc):

-fconstant-string-class=NSConstantString