shutter release sound causing problems

Discussion in 'iOS Programming' started by gbenna, Aug 2, 2012.

  1. macrumors member

    Jul 27, 2011
    I have an app that has three tabs. In tabview THREE I enters the name of an item and then takes a picture of that item. The picture is then saved into the app's documents directory and into the photo library. The strange thing is that when I take the picture the shutter release sound does't take place even though the picture is taken and saved in both places. The shutter release sound takes place but in a different place and has an unwanted effect.

    In tabview ONE I have a tableview. When you choose the (pictures) row a flow view of photos taken in tabview THREE opens up. When you double tap on a picture that picture shows up full size in another view. When this large picture view opens THE SHUTTER RELEASE SOUND IS FINALY MADE.

    I have researched this and haven't found any helpful suggestions.

    Could someone look at my code and tell me what I've done wrong?

            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            if((UIButton *) sender == save){
                picker.sourceType =  UIImagePickerControllerSourceTypeCamera ;}
            else if((UIButton*)sender == getPhoto){  
                 picker.sourceType =  UIImagePickerControllerSourceTypeSavedPhotosAlbum ;}
            [self presentModalViewController: picker animated:YES];
    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)  picker
        [picker dismissModalViewControllerAnimated:YES];
    - (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        picker.allowsEditing = YES;
       NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [documentPaths objectAtIndex:0];
        NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
        fullPath = [fullPath stringByAppendingFormat:@".jpg"];
        NSError *error;
        //try this to documents
        float actualHeight = image.size.height;
        float actualWidth = image.size.width;
        float imgRatio = actualWidth/actualHeight;
        float maxRatio = 280.0/210.0;
        if(imgRatio !=maxRatio){
            if (imgRatio < maxRatio){
                imgRatio =280.0/actualHeight;
                actualWidth =imgRatio * actualWidth;
                actualHeight = 280.0;
            else {
                imgRatio = 210.0/actualWidth;
                actualHeight = imgRatio * actualHeight;
                actualWidth = 210.0;
        CGRect rect = CGRectMake(0.0, 0.0,actualWidth,actualHeight);
        [image drawInRect:rect];
        image = UIGraphicsGetImageFromCurrentImageContext();
        [UIImageJPEGRepresentation(image, 0.5) writeToFile:fullPath atomically:YES]; 
           NSFileManager *fileMgr = [NSFileManager defaultManager];
        NSString *documentsDirectory2 = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSLog(@"Documents directory: %@", [fileMgr contentsOfDirectoryAtPath:documentsDirectory2 error:&error]);
        UIAlertView *alert;
        // Unable to save the image  
        if (error)
            alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR", nil) 
                                               message:NSLocalizedString(@"UNABLETOSAVE", nil) 
                                              delegate:self cancelButtonTitle:@"Ok" 
        else // All is well
            alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SUCCESS!", nil) 
                                               message:NSLocalizedString(@"SAVED", nil) 
                                              delegate:self cancelButtonTitle:@"Ok" 
        [alert show];
        self.photoView2.image = image;
        [self dismissModalViewControllerAnimated:YES];

Share This Page