2012-03-10 35 views
0

當我通過Xcode部署到我的iPhone時,我的應用似乎工作正常,但現在它下載時它在應用商店中,它崩潰了。它一定爲蘋果工作,就像這樣,它永遠不會通過審查?來自應用商店的ALAssetLibrary錯誤,但不是從Xcode部署的

我試過其他手機,但他們也崩潰。從查看崩潰日誌,下面的代碼是關注的領域。

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的部署到手機

任何人都可以提供一些線索爲我點亮這個?

回答

0

爲了避免coredata和線程問題,請確保: 1)您只爲應用程序的整個生命週期創建一個alassetslibrary實例。因此,建議您在appdelegate或dispatch_once中初始化您的assetslibrary實例。2)確保在主線程上創建alassetslibrary實例。

乾杯,

亨德里克

相關問題