2016-08-11 5 views
0

Die CRASH ist:Absturz Nur in iPod

Diese Anwendung von einem Hintergrund-Thread der automatischen Layout-Engine wird modifiziert, der Motor Korruption und seltsame Abstürze führen kann. Dies wird eine Ausnahme in einer zukünftigen Version verursachen.

Es ist klar, dass das Problem ist, dass jedes Mal, wenn die UI geändert wird, muss auf dem Hauptthread getan werden. Theoretisch könnte dies

dispatch_async(dispatch_get_main_queue(), { 
    // code here 
}) 

arbeiten Meine Funktion ist:

- (void)requestInBlock:(NSString *)keyThumbnails withArrayQuantity:(NSMutableArray *)quantityArray andOriginalQuantity:(NSInteger)originalQuantity 
{ 
    int limit = 5; 

    NSMutableArray *arrayFive = [[NSMutableArray alloc] init]; 
    NSInteger idQuantityOriginalCount = [quantityArray count]; 

    for (NSInteger i = 0; i < MIN(limit, idQuantityOriginalCount); i ++) { 
     [arrayFive addObject:[quantityArray objectAtIndex:0]]; 
     [quantityArray removeObjectAtIndex:0]; 
    } 

    NSInteger idLimitArrayCount = [arrayFive count]; 

    NSInteger __block countProductsRequestLimit = 0; 
    for (NSNumber *j in arrayFive) { 
     UIImageView * thumbnailImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xposThumbnails, 0, ratio * 2, 47)]; 
     [thumbnailsView addSubview:thumbnailImageView]; 

     NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://s3-us-west-2.amazonaws.com/xxxxxxxxxxxxxx/%@_%@.jpg",keyThumbnails,j]]; 

     [Utils loadFromURL:imageUrl callback:^(UIImage *image) { 

      countProductsRequestLimit++; 
      countThumbnailsGlobal++; 

      [thumbnailImageView setImage:image]; 
      [cutVideoScroll addSubview:thumbnailsView]; 

      if (!image) { 
       NSMutableDictionary *collectInfoFailImage = [[NSMutableDictionary alloc] init]; 
       [collectInfoFailImage setValue:thumbnailImageView forKey:@"image"]; 
       [collectInfoFailImage setValue:imageUrl forKey:@"imageUrl"]; 
       [thumbnailsWithError addObject:collectInfoFailImage]; 
       collectInfoFailImage = nil; 
      } 
      if (countThumbnailsGlobal == originalQuantity) { 
       [arrayFive removeAllObjects]; 
       [self performSelector:@selector(reloadThumbnailsWithError) withObject:nil afterDelay:3]; 
      } else if (idLimitArrayCount == countProductsRequestLimit) { 
       [arrayFive removeAllObjects]; 
       [self requestInBlock:keyThumbnails withArrayQuantity:quantityArray andOriginalQuantity:originalQuantity]; 
      } 
     }]; 

     xposThumbnails += (ratio * 2); 
    } 
    loadingTimeLine.layer.zPosition = -1; 
    lblloadingTimeLine.layer.zPosition = -1; 
} 

Ich denke, der Fehler hier loadFromURL geschieht. (Es ist hier nicht sicher, denn in allen Geräten mit mir meine Tests zu tun, geschieht dies nie jemand außer mir informiert und schickte mir Fehlerprotokolle)

Meine Frage ist:

  • Welcher Teil dieses Codes könnte das AutoLayout modifizieren, vielleicht [cutVideoScroll addSubview:thumbnailsView];?
  • Warum nur auf einem iPod auftritt?

UPDATE:

Ich teste mit.

dispatch_async(dispatch_get_main_queue(), ^{ 
    [thumbnailImageView setImage:image]; 
    [cutVideoScroll addSubview:thumbnailsView]; 
}); 

Fehler aber bestehen.

Danke für Ihre Zeit.

Antwort

0

Es scheint eine Kombination von 2 Dingen zu sein.

dispatch_async(dispatch_get_main_queue(), ^{ 
    [thumbnailImageView setImage:image]; 
    [cutVideoScroll addSubview:thumbnailsView]; 
}); 

und in allen Fällen wurde er zu thumbnailImageView die Validierung if (! image)image unabhängig hinzugefügt

0

Sie haben es richtig, Hinzufügen von Unteransicht zum Anzeigen Trigger layoutSubviews. Sie sollten AddViews nur im Hauptthread hinzufügen.

Vielleicht haben Sie etwas Code speziell für iPhone/iPod in jeder Methode, die Sie überschreiben?