【问题标题】:Crash Only in iPod仅在 iPod 中崩溃
【发布时间】:2016-12-18 05:53:23
【问题描述】:

CRASH 是:

此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。

很明显,问题是每次更改ui都必须在主线程上完成。理论上这可能有效

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

我的功能是:

- (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;
}

我认为错误发生在这里loadFromURL。 (对此不确定,因为在我进行测试的所有设备中,这从未发生过,外部人员通知我并向我发送了错误日志

我的问题是:

  • 这段代码的哪一部分可能正在修改自动布局,可能是[cutVideoScroll addSubview:thumbnailsView];
  • 为什么只出现在 iPod 上?

更新:

我正在测试。

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

但错误仍然存​​在。

感谢您的宝贵时间。

【问题讨论】:

    标签: ios objective-c crash autolayout


    【解决方案1】:

    你没看错,添加子视图到视图触发器layoutSubviews。所以你应该只在主线程中添加视图。

    也许您有一些专门用于 iPhone / iPod 的代码,您可以覆盖任何方法?

    【讨论】:

      【解决方案2】:

      这似乎是两件事的结合。

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

      在所有情况下,他都被添加到thumbnailImageViewimage,无论验证if (! image)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-09
        • 2012-09-29
        • 2012-11-28
        • 1970-01-01
        • 2011-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多