Domanda

Sto sviluppando un app iOS che si basa su ALAssetsLibrary api (disponibile dal 4,0), lo uso per recuperare tutte le immagini ei video salvati sul dispositivo ed è stato abbastanza semplice per farlo. In ogni caso, non appena ho installato iOS 4.3.4 sul mio iPhone 4, il mio codice ha smesso di funzionare. La linea, che invoca il recupero non fa nulla! Il codice è il seguente (e funziona bene su iOS 4.3.3):

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

ALAssetsGroupEnumerationResultsBlock assetsEnumerator = ^(ALAsset *result, NSUInteger index, BOOL *stop) { 
// handle asset
    };

ALAssetsLibraryGroupsEnumerationResultsBlock groupsEnumerator = ^(ALAssetsGroup *group, BOOL *stop) { 
// handle group
    };

    ALAssetsLibraryAccessFailureBlock failHandler = ^(NSError *error) {
// handle error
    };


[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:groupsEnumerator failureBlock:failHandler];

sembra che enumerateGroupsWithTypes: usingBlock: failureBlock: non vengono mai chiamati, perché nessuno dei miei blocchi vengono eseguiti ... e nessun errore viene generato! Perché? Cosa posso fare?

ps: ho cercato di cambiare argomento "tipi", ma non è questo il problema

!
È stato utile?

Soluzione

I don't understand why (Apple in this moment I'm hating you!), but ALAssetsLibrary in iOS 4.3.4 does not allow fetching in a background thread (I was running a series of NSOperations in a NSOperationQueue). I solved by creating a little wrapper using performSelectorOnMainThread.

EDIT:

After a code refactoring and the upgrade to iOS 5, I finally realized that the problem is actually related to how ALAssetsLibrary works, there is no need to use performSelectorOnMainThread. I wrote a post on it here.

Altri suggerimenti

Something very important:

The user must allow location services for your app.

As written in apple doc for enumerateGroupsWithTypes:usingBlock:failureBlock method.

Special Considerations

This method will fail with error ALAssetsLibraryAccessGloballyDeniedError if the user has not enabled Location Services (in Settings > General).

Maybe you should handle this case by displaying an alert to the user.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top