jose920405 jose920405 - 6 months ago 32
iOS Question

Crash Only in iPod



This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.

It is clear that the problem is that every time the ui is changed must be done on the main thread. In theory this might work

dispatch_async(dispatch_get_main_queue(), {
// code here

My Function is:

- (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:@"",keyThumbnails,j]];

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


[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;

I think the mistake is happening here
. (It is not sure about this, because in all devices with I do my tests, this never happens, someone outside informed me and sent me error logs)

My question is:

  • which part of this code may be modifying the autoLayout, maybe
    [cutVideoScroll addSubview:thumbnailsView];

  • Why only occurs on an iPod?


I'm testing with.

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

But error persist.

Thanks for your time.


It seems to be a combination of 2 things.

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

and in all cases, he was added to thumbnailImageView the image regardless validation if (! image)