0

我的应用程序在通过 Xcode 部署到我的 iPhone 时似乎工作正常,但是现在当我下载它时它在应用商店中,它崩溃了。它一定对苹果有用,因为它永远不会通过审查????

我尝试过其他手机,但它们也崩溃了。通过查看崩溃日志,下面的代码是值得关注的领域。

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
    // Do a tasks in the background
    library = [[ALAssetsLibrary alloc] init];   

    NSMutableArray *itemFileName = [[NSMutableArray alloc] init];

    for (Item *it in tag.Items) {
        [itemFileName addObject:it.name];
    }

    void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *asset, NSUInteger index, BOOL *stop) {
        if(asset != NULL && [asset valueForProperty:ALAssetPropertyType] == ALAssetTypePhoto) {

            ALAssetRepresentation *rep = [asset defaultRepresentation];
            NSString *fileName = [rep filename];



            if ([itemFileName containsObject:fileName]) {
                AssetView *assetView = [[AssetView alloc] initWithAsset:asset];
                assetView.delegate = self;
                assetView.fileName = fileName;
                //assetView.index = counter;
                [self.assetViews addObject:assetView];
                //NSLog(@"%i",index);

            }

        }
    };

    void (^assetGroupEnumerator)( ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
        if(group != nil) {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }
        else{
            //[self performSelectorOnMainThread:@selector(reloadTableView) withObject:nil waitUntilDone:YES];
            // Hide the HUD in the main tread 
            dispatch_async(dispatch_get_main_queue(), ^{
                [self reloadTableView];
                [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
                [self loadImageTags];

                if([self.assetViews count] != [tag.Items count]){
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" 
                                                                    message:@"Some items have been deleted from the device. If none remain for this tag it will be deleted."  
                                                                   delegate:self 
                                                          cancelButtonTitle:nil 
                                                          otherButtonTitles: @"OK", nil];
                    [alert show];

                    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
                    hud.labelText = @"Cleaning...";

                    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
                        [self clearupOrphanedItems];

                        dispatch_async(dispatch_get_main_queue(), ^{
                            [MBProgressHUD hideHUDForView:self.navigationController.view animated:YES];
                        });

                    });
                }                
            });
        }
    };

    // Group Enumerator Failure Block
    void (^assetGroupEnumberatorFailure)(NSError *) = ^(NSError *error) {

        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"Album Error: %@ - %@", [error localizedDescription], [error localizedRecoverySuggestion]] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        [alert show];

        NSLog(@"A problem occured %@", [error description]);                                     
    };  

    // Enumerate Albums
    [library enumerateGroupsWithTypes:ALAssetsGroupAll
                           usingBlock:assetGroupEnumerator 
                         failureBlock:assetGroupEnumberatorFailure];   //HERE IS WHERE IT DIES!!!     

});

我不确定问题是否是由于在块内实例化 ALAssetLibrary 造成的,因为它可以在调试期间正常工作,甚至只是通过 Xcode 部署到电话

任何人都可以为我阐明这一点吗?

4

1 回答 1

0

为避免 coredata 和线程问题,请确保:1) 在应用程序的整个生命周期中只创建一个 alassetslibrary 实例。因此,它建议您在 appdelegate 或使用 dispatch_once 初始化您的 assetslibrary 实例 2) 确保在主线程上创建 alassetslibrary 实例。

干杯,

亨德里克

于 2012-03-18T21:55:29.400 回答