2012-05-23 22 views
0

我分叉這個偉大的鈦模塊訪問ALAsset。 https://github.com/amigoni/titanium-mobile-alasset-module鈦的ALAsset模塊在模擬器上工作,但在設備上崩潰任何提示?

我正在嘗試訪問圖片數據和信息。它似乎在模擬器中正常工作,但不在設備上。

這裏就是我懷疑的代碼是

-(void)assetThumbnails:(id)args 
{ 
ENSURE_UI_THREAD_1_ARG(args); 
ENSURE_SINGLE_ARG(args,NSDictionary); 

id onthumb  = [args objectForKey:@"thumbnailCallback"]; 
NSString *group = [args objectForKey:@"group"]; 
ENSURE_STRING_OR_NIL(group); 
int page  = [TiUtils intValue:[args objectForKey:@"page"] def:1] - 1; 
int perPage  = [TiUtils intValue:[args objectForKey:@"perPage"] def:25]; 

int fromIndex = page * perPage; 
int toIndex  = fromIndex + perPage; 

NSUInteger groupTypes = ALAssetsGroupSavedPhotos; 
if(group == nil){ 
    group = @"savedPhotos"; 
} 
if([group isEqualToString:@"savedPhotos"]){ 
    groupTypes = ALAssetsGroupSavedPhotos; 
} else if([group isEqualToString:@"photoStream"]){ 
    groupTypes = ALAssetsGroupPhotoStream; 
} else if([group isEqualToString:@"faces"]){ 
    groupTypes = ALAssetsGroupFaces; 
} else if([group isEqualToString:@"all"]){ 
    groupTypes = ALAssetsGroupAll; 
} 
NSMutableArray *assets = [[NSMutableArray alloc] init]; 
RELEASE_TO_NIL(thumbCallback); 
thumbCallback = [onthumb retain]; 
void (^assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){ 
    if(group != nil) { 
     [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { 
      if(result != nil) 
      { 
       if((index >= fromIndex) && (index <= toIndex)){ 
        NSURL *url = [[result defaultRepresentation] url]; 
        NSString *sUrl = [url absoluteString]; 
        NSDictionary *metadata = result.defaultRepresentation.metadata; 
         UIImage *thumbnail = [UIImage imageWithCGImage:[result thumbnail]]; 
         NSDictionary *event = [NSDictionary 
               dictionaryWithObjectsAndKeys: 
               [[[TiBlob alloc] initWithImage:thumbnail] autorelease], 
               @"thumbnail", 
               NUMINT(index), 
               @"index", 
               sUrl, 
               @"url", 
               metadata, 
               @"metadata", 
               nil]; 
         [assets addObject:event]; 
       } 
      } else { 
       if (thumbCallback!=nil) 
       { 
        NSDictionary *event = [NSDictionary dictionaryWithObjectsAndKeys:assets,@"assets", nil]; 
        [self _fireEventToListener:@"onThumbnail" withObject:event listener:thumbCallback thisObject:nil]; 
        [assets release]; 
       } 
      } 
     }]; 
    } 
}; 

ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 

[library enumerateGroupsWithTypes:groupTypes 
         usingBlock:assetGroupEnumerator 
        failureBlock:^(NSError *error) {}]; 
[library release]; 
} 

有趣的是,該代碼似乎第26項之後崩潰。正如你從上面的代碼中看到的那樣,將成爲第二頁的第一頁。

我真的不太瞭解Objective C並且正在尋找一些幫助。

謝謝

回答

0

也許[發佈資產]引發異常。我的情況是這樣的。

在分配資產時,[[[[[NSMutableArray alloc] init] autorelease]並刪除該行; 異常不會升高。

相關問題