Note that there are some explanatory texts on larger screens.

plurals
  1. POALAssetsLibrary - crash after receiving ALAssetsLibraryChangedNotification
    primarykey
    data
    text
    <p>Part of my app has a photo browser, somewhat similar to Apple's Photos app, with an initial view controller to browse photo thumbnails and a detail view that's shown when you tap on a photo.</p> <p>I'm using ALAssetsLibrary to access photos, and I pass an array of ALAsset URL's to my detail view controller so you can swipe from one photo to the next.</p> <p>Everything works great, until I receive an ALAssetsLibraryChangedNotification while swiping from one photo to another (in the detail view controller), which often results in a crash:</p> <blockquote> <p>NOTIFICATION: the asset library changed // my own NSLog for when the notification occurs</p> <p>loading assets... // my own NSLog for when I start reloading assets in the thumbnail browser</p> <p>Assertion failed: (size == bytesRead), function -[ALAssetRepresentation _imageData], file /SourceCache/AssetsLibrary/MobileSlideShow-1373.58.1/Sources/ALAssetRepresentation.m, line 224.</p> </blockquote> <p>The specific line of code it crashes on, is in calling [currentRep metadata] as shown here:</p> <pre><code>- (void)someMethod { NSURL *assetURL = [self.assetURLsArray objectAtIndex:index]; ALAsset *currentAsset; [self.assetsLibrary assetForURL:assetURL resultBlock:^(ALAsset *asset) { [self performSelectorInBackground:@selector(configureDetailViewForAsset:) withObject:asset]; } failureBlock:^(NSError *error) { NSLog(@"failed to retrieve asset: %@", error); }]; } - (void)configureDetailViewForAsset:(ALAsset *)currentAsset { ALAssetRepresentation *currentRep = [currentAsset defaultRepresentation]; if (currentAsset != nil) { // do some stuff } else { NSLog(@"ERROR: currentAsset is nil"); } NSDictionary *metaDictionary; if (currentRep != nil) { metaDictionary = [currentRep metadata]; // do some other stuff } else { NSLog(@"ERROR: currentRep is nil"); } } </code></pre> <p>I understand that once a notification is received, it invalidates any references to ALAsset and ALAssetRepresentation objects... but how am I supposed to deal with the situation where it invalidates something right in the middle of trying to access it?</p> <p>I've tried setting a BOOL, right when receiving the notification to completely abort and prevent [currentRep metadata] from ever being called, but even that doesn't catch it every time:</p> <pre><code>if (self.receivedLibraryChangeNotification) { NSLog(@"received library change notification, need to abort"); } else { metaDictionary = [currentRep metadata]; } </code></pre> <p>Is there anything I can do? At this point I'm almost ready to give up on using the ALAssetsLibrary framework.</p> <p>(note this unresolved thread on the Apple dev forums describing the same issue: <a href="https://devforums.apple.com/message/604430" rel="nofollow noreferrer">https://devforums.apple.com/message/604430</a> )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload