Showing posts with label iPhone. Show all posts
Showing posts with label iPhone. Show all posts

Thursday, July 5, 2012

Alternative way to replace UIGetScreenImage()

CGImageRef screen = UIGetScreenImage();

The above code is one line of code to capture the screen, but Apple does not open the above API UIGetScreenImage() for the public app. i.e. fail to upload to Apple for approval. So the alternative way to capture screen and save it are listed as below.

- (void)captureAndSaveImage
{    
    
    // Capture screen here... and cut the appropriate size for saving and uploading
    UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   
    // crop the area you want 
    CGRect rect;
    rect = CGRectMake(0, 10, 300, 300);    // whatever you want
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
    UIImage *img = [UIImage imageWithCGImage:imageRef]; 
    CGImageRelease(imageRef);
    UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    imageView.image = img; // show cropped image on the ImageView     
}

// this is option to alert the image saving status
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
    
    // Unable to save the image  
    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Dismiss" 
                                 otherButtonTitles:nil];
    else // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    [alert show];
    [alert release];
}


Tuesday, June 26, 2012

php: get input and write text file, then return

Put the following codes in the server side to receive the inputs from Apps.

<?php
     
    // assign the input to the variables
    $method = $_POST['method'];
    $name = $_POST['name']; // variable to be received by server
    $id = $_POST['userID']; // variable to be received by server
    echo " user name: ".$name ." id: ". $id. " method: ". $method; // echo the received data to the Apps
    
    
    // write text file with above two variables
    $file = "file.txt";
    $fh = fopen( $file, 'w' );
    $carriageReturn = "\n";
    fwrite( $fh, $method );
    fwrite( $fh, $carriageReturn );
    fwrite( $fh, $name );
    fwrite( $fh, $carriageReturn );
    fwrite( $fh, $id );
    fclose( $fh );
   
    
    
?>

Monday, June 18, 2012

No previous prototype for function




How to handle the Xcode warning “no previous prototype for function…”?


Go to project's Build Settings. Search for "prototype". There is an option called "Missing Function Prototypes" under Apple LLVM complier 3.1 warning; disable it. 
Optionally, you can also do this to the specific target(s) in question.