2012-12-18 4 views
1

Dans mon application, je suis en train de faire une seule image en utilisant l'appareil photo, mais il se bloque tout le temps sans raison.iOS UIImagePickerController accident étrange sur ios 6

Je fais face à ce problème depuis longtemps, donc je suis fournir un code qui peut sembler inutile: dans le viewcontroller:

- (id) init 
{ 
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) 
    { 
     self = [super initWithNibName:@"WCAddNewWatchViewController_iPhone" bundle:[NSBundle mainBundle]]; 
    }else 
    { 
     self = [super initWithNibName:@"WCAddNewWatchViewController_iPad" bundle:[NSBundle mainBundle]]; 
    } 

    if(self) 
    { 

    } 

    return self; 
} 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 

    [[self navigationItem]setRightBarButtonItem:self.AddButton]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)ChangeImageButtonTapped:(id)sender { 
    UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    { 
     picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
    else 
    { 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    } 

    picker.mediaTypes = @[(NSString *) kUTTypeImage]; 
    picker.allowsEditing = NO; 
    [picker setDelegate:self]; 

    [self presentViewController:picker animated:YES completion:nil]; 

} 

#pragma mark UIImagePickerControllerDelegate 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    NSString *mediaType = info[UIImagePickerControllerMediaType]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) { 
     UIImage *image = info[UIImagePickerControllerOriginalImage]; 
     selectedImage = image; 
    // self.watchImageView.image = selectedImage; 

    } 

    NSLog(@"no crash!!!!"); //that's a lie... 
} 

Il n'y a pas un message de crash, le journal écrit que l'application reçue avertissements de mémoire, puis se bloque. Le journal de l'appareil dit:

TIL out-of-mémoire tueur est appelé « Jetson » sur iOS

Quelqu'un peut-il regarder mon code et me dire ce que je fais mal?

+1

Il y a TOUJOURS une raison. Quel est votre message d'erreur et votre journal de panne? – Bot

+0

Il n'y a pas de message d'erreur, le journal écrit que l'application a reçu des avertissements de mémoire, puis se bloque. Le journal de l'appareil indique: TIL le tueur de mémoire insuffisante est appelé "jetsam" sur iOS. –

+0

il y a un crashlog. dans l'organiseur – Bot

Répondre

3

vous avez été tué par le processus de surveillance parce que vous na pas gérer les avertissements de mémoire (ios a processus qui surveille mem utilisation & temps de démarrage de l'application et tue des applications qui semblent aller voyous »)

BTW: TIL = Aujourd'hui, je appris: D

utiliser une version réduite de l'image pour l'affichage.

- (UIImage *)scaledCopyOfSize:(CGSize)newSize { 
    CGImageRef imgRef = self.CGImage; 

    CGFloat width = CGImageGetWidth(imgRef); 
    CGFloat height = CGImageGetHeight(imgRef); 

    CGAffineTransform transform = CGAffineTransformIdentity; 
    CGRect bounds = CGRectMake(0, 0, width, height); 
    if (width > newSize.width || height > newSize.height) { 
     CGFloat ratio = width/height; 
     if (ratio > 1) { 
      bounds.size.width = newSize.width; 
      bounds.size.height = bounds.size.width/ratio; 
     } 
     else { 
      bounds.size.height = newSize.height; 
      bounds.size.width = bounds.size.height * ratio; 
     } 
    } 

    CGFloat scaleRatio = bounds.size.width/width; 
    CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef)); 
    CGFloat boundHeight; 
    UIImageOrientation orient = self.imageOrientation; 
    switch(orient) { 

     case UIImageOrientationUp: //EXIF = 1 
      transform = CGAffineTransformIdentity; 
      break; 

     case UIImageOrientationUpMirrored: //EXIF = 2 
      transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0); 
      transform = CGAffineTransformScale(transform, -1.0, 1.0); 
      break; 

     case UIImageOrientationDown: //EXIF = 3 
      transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height); 
      transform = CGAffineTransformRotate(transform, M_PI); 
      break; 

     case UIImageOrientationDownMirrored: //EXIF = 4 
      transform = CGAffineTransformMakeTranslation(0.0, imageSize.height); 
      transform = CGAffineTransformScale(transform, 1.0, -1.0); 
      break; 

     case UIImageOrientationLeftMirrored: //EXIF = 5 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width); 
      transform = CGAffineTransformScale(transform, -1.0, 1.0); 
      transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationLeft: //EXIF = 6 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(0.0, imageSize.width); 
      transform = CGAffineTransformRotate(transform, 3.0 * M_PI/2.0); 
      break; 

     case UIImageOrientationRightMirrored: //EXIF = 7 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeScale(-1.0, 1.0); 
      transform = CGAffineTransformRotate(transform, M_PI/2.0); 
      break; 

     case UIImageOrientationRight: //EXIF = 8 
      boundHeight = bounds.size.height; 
      bounds.size.height = bounds.size.width; 
      bounds.size.width = boundHeight; 
      transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0); 
      transform = CGAffineTransformRotate(transform, M_PI/2.0); 
      break; 

     default: 
      [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"]; 

    } 

    if (UIGraphicsBeginImageContextWithOptions) { 
     UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 
               /* 0.0f will scale to 1.0/2.0 depending on if the 
               device has a high-resolution screen */ 
               0.0f); 
    } else { 
     UIGraphicsBeginImageContext(bounds.size); 
    } 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) { 
     CGContextScaleCTM(context, -scaleRatio, scaleRatio); 
     CGContextTranslateCTM(context, -height, 0); 
    } 
    else { 
     CGContextScaleCTM(context, scaleRatio, -scaleRatio); 
     CGContextTranslateCTM(context, 0, -height); 
    } 

    CGContextConcatCTM(context, transform); 

    CGContextDrawImage(context, CGRectMake(0, 0, width, height), imgRef); 
    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return imageCopy; 
} 
+0

déjà essayé, mais cela n'a pas fonctionné. pourriez-vous fournir du code s'il vous plaît? –

+0

J'ai fourni une méthode d'échelle –

+0

Cela a résolu mon problème! Très agréable! Je vous remercie! –

Questions connexes