2013-07-08 14 views
4

我使用grabKit爲了允許用戶將他們的Instagram,Facebook和本地圖片導入到我的應用程序。問題出在照片是本地的時候。在這種情況下,我使用一種在用戶選擇照片時起作用的方法。使用ALAsset從GRKPhoto UIImage

標準的代碼,我才能做到發現如下:

 
- (void)picker:(GRKPickerViewController*)picker didSelectPhoto:(GRKPhoto *)photo{ 

    [popover dismissPopoverAnimated:YES]; 

    GRKImage *originalImage = [photo originalImage]; 

    NSLog(@" the URL of the original image of the first selected photo is : %@", originalImage.URL); 
    NSLog(@" the size of this image is : %d x %d ", originalImage.width, originalImage.height); 

    // If the url begins with assets-library:// 
    if ([[originalImage.URL absoluteString] hasPrefix:@"assets-library://"]){ 

     // Instantiate a library 
     ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init]; 

     // Ask for the "Asset" for the URL. An asset is a representation of an image in the Photo application. 
     [library assetForURL:originalImage.URL 
       resultBlock:^(ALAsset *asset) { 

        // Here, we have the asset, let's retrieve the image from it 
        CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage]; 

        // From the CGImage, let's build an UIImage 
        UIImage * fullResImage = [UIImage imageWithCGImage:imgRef]; 

        NSLog(@" The UIImage for URL %@ is %@", originalImage.URL, fullResImage); 

       } failureBlock:^(NSError *error) { 
        // Something wrong happened. 
       }]; 
} 

做一些調試,我發現該應用程序崩潰時,我嘗試從ALAsset,ERGO得到CGImageRef,在這一行:CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];

如果它可以幫助解決我的問題,我在控制檯得到的消息是:

 
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan 653]' 

*** First throw call stack: 

(0x42f8012 0x2ad9e7e 0x42f7deb 0x161ee0b 0x161efa5 0x161f6eb 0x174fe53 0x18191c0 0x181941a 0x21fad 0x219f1 0x13de70 0xf3c03 0x1c0f42f 0x1c21182 0x1c21394 0x2aed705 0x181b93c 0x181b9ac 0x2aed705 0x181b93c 0x181b9ac 0x19d51d3 0x42c0afe 0x42c0a3d 0x429e7c2 0x429df44 0x429de1b 0x3b9d7e3 0x3b9d668 0x170dffc 0x69432 0x30f5) 

libc++abi.dylib: terminate called throwing an exception 

感謝您的時間和興趣!

回答

2

通常CALayerInvalidGeometryNAN是CALayer幀無效設置的結果,而CALayer幀的設置可能由view.frame設置。這可能是某個地方的圖層位置/變換設置不正確。既然你不直接這樣做,它似乎是一個與Grabkit錯誤。將它歸檔here

您可以考慮使用F7進入CGImageRef imgRef = [[asset defaultRepresentation] fullResolutionImage];,以提供有關崩潰的更多信息至Grabkit