xcode snippets

How to configure and use ASIHttpRequest with XCode

Tagged http, objective-c, asihttprequest, xcode  Languages objectivec

Get ASIHttpRequest from GitHub

$ cd project-dir
$ git clone git://github.com/pokeb/asi-http-request.git
mkdir -p lib/ASIHttpRequest
mv asi-http-request/Classes/* lib/ASIHttpRequest

Link required frameworks

In Groups & Files in XCode, right-click Frameworks > Linked Frameworks choose Add Existing Frameworks.

Select CoreServices.framework. Do the same for SystemConfiguration.framework.

Next add libz.1.2.3.dylib by selecting Add Existing Files from the same menu. The full path to this file is /Developer/SDKs/MacOSX10.5.sdk/usr/lib/libz.1.2.3.dylib

Making asynchronous requests

- (void)requestDone:(ASIHTTPRequest *)request
{
    NSString *response = [request responseString];
    NSLog ( @"Response %@", response );

}

- (void)requestWentWrong:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog ( @"Something wrong" );
}

- (void)requestURL()
{
    NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
    ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
    
    [request setDelegate:self];
    [request setDidFinishSelector:@selector(requestDone:)];
    [request setDidFailSelector:@selector(requestWentWrong:)];
    
        [networkQueue addOperation:request];
    [networkQueue go];
}

Making synchronous requests

NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
    ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
    [request start];
    NSError *error = [request error];
    
    if (!error) {
        NSString *response = [request responseString];
        NSLog ( @"Response: %@", response );
    } else {
        NSLog ( @"Something went wrong" );
    }

Fix for "Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain"

Tagged certificate, iphone, titanium, xcode  Languages 

I got this error the other day:

Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain

The fix for me was this:

  • Login to iPhone Developer Program
  • Click on Certificates
  • Under Current Development Certificates click on the button to download your certificate. It gets saved as developer_identity.cer.
  • Open the Keychain tool
  • Make sure the "login" keychain is selected in the left pane.
  • Make sure that "login" is the default keychain (right-click on the login item to do this)
  • Drag the developer_identity.cer file to the login keychain's list of certificates.
  • Build your app