1. "Get cookies using iPhone SDK"

    Thu 14 May 2009

    NSHTTPURLResponse * response;

    NSError * error;

    NSMutableURLRequest request;

    request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://google.com/"]

    cachePolicy:NSURLRequestReloadIgnoringCacheData 

    timeoutInterval:60] autorelease];

    NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

     

    NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]);

    NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://google.com/"]];

    NSLog ...

    read more
  2. "Create openGL texture"

    Wed 13 May 2009

    - (void)createGLTexture:(GLuint *)texName fromCGImage:(CGImageRef)img

    {

    GLubyte *spriteData = NULL;

    CGContextRef spriteContext;

    GLuint imgW, imgH, texW, texH;

    imgW = CGImageGetWidth(img);

    imgH = CGImageGetHeight(img);

    // Find smallest possible powers of 2 for our texture dimensions

    for (texW = 1; texW < imgW; texW *= 2) ;

    for (texH = 1; texH < imgH; texH *= 2) ;

    // Allocated memory needed ...

    read more
  3. "Resize UITableView to fit toolbar"

    Tue 12 May 2009

    CGFloat toolbarHeight = 50;

    CGRect mainViewBounds = self.view.bounds;

    [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),

    CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),

    CGRectGetWidth(mainViewBounds),

    toolbarHeight)];

     

     

    UIView *footerView = [[[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 

    CGRectGetMinY(mainViewBounds), 

    CGRectGetWidth(mainViewBounds), 

    toolbarHeight+5)] autorelease];

     

    tableView = [[UITableView alloc

    initWithFrame:CGRectMake(mainViewBounds.origin.x, mainViewBounds.origin.y, mainViewBounds.size.width ...

    read more
  4. "Save image to image library"

    Tue 12 May 2009

    -(void)savePictureToLibrary{    

        UIImage *img = [[UIImage imageNamed:@"image.png"];

        UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), self);

    }

     

     

    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{

        NSString *str = @"Saved!!!";

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];

        [alert show];

    }


    read more
  5. "Create UIButton/button with images"

    Mon 11 May 2009

    UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

    playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);

    [playButton setTitle:@"Play" forState:UIControlStateNormal];

    playButton.backgroundColor = [UIColor clearColor];

    [playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];

     

    UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];

    UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];

    [playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal ...

    read more
  6. "Check if device connected to the Internet"

    Mon 11 May 2009

    #import <SystemConfiguration/SCNetworkReachability.h>

    #include <netinet/in.h>

     

    - (BOOL) connectedToNetwork

    {

        // Create zero addy

        struct sockaddr_in zeroAddress;

        bzero(&zeroAddress, sizeof(zeroAddress));

        zeroAddress.sin_len = sizeof(zeroAddress);

        zeroAddress.sin_family = AF_INET;

        // Recover reachability flags

        SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);

        SCNetworkReachabilityFlags flags;

        BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);

        CFRelease(defaultRouteReachability);

        if (!didRetrieveFlags)

        {

            printf("Error ...

    read more
  7. "Alert (UIAlertView) with text field (UITextField)"

    Mon 11 May 2009

    // open a alert with text field,  OK and cancel button

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send Email" message:@" "

           delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Send", nil];

     

    CGRect frame = CGRectMake(14, 45, 255, 23);

    if(!emailField) {

    emailField = [[UITextField alloc] initWithFrame:frame];

    emailField.borderStyle = UITextBorderStyleBezel;

    emailField.textColor = [UIColor blackColor];

    emailField.textAlignment = UITextAlignmentCenter;

    emailField ...

    read more
  8. "Generate PDF on iPhone"

    Mon 11 May 2009

    //Create empty PDF context on iPhone for later randering in it

    -(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path

    {

        CGContextRef myOutContext = NULL;

        CFURLRef url;

        url = CFURLCreateWithFileSystemPath (NULL, // 1

    path,

    kCFURLPOSIXPathStyle,

    false);

        if (url != NULL) {

            myOutContext = CGPDFContextCreateWithURL (url,// 2

      &inMediaBox,

      NULL);

            CFRelease(url);// 3

        }

        return myOutContext;// 4

    }

     

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ...

    read more

« Page 8 / 13 »