-(Void) loadAssets {
// Initialise
_ Assets = [NSMutableArray new];
_ AssetLibrary = [[ALAssetsLibrary alloc] init];
// Run in the background as it takes a while to get all assets from the library
Dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
NSMutableArray * assetGroups = [[NSMutableArray alloc] init];
NSMutableArray * assetURLDictionaries = [[NSMutableArray alloc] init];
// Process assets
Void (^ assetEnumerator) (ALAsset *, NSUInteger, BOOL *) = ^ (ALAsset * result, NSUInteger index, BOOL * stop ){
If (result! = Nil ){
If ([[result valueForProperty: ALAssetPropertyType] isEqualToString: ALAssetTypePhoto]) {
[AssetURLDictionaries addObject: [result valueForProperty: ALAssetPropertyURLs];
NSURL * url = result. defaultRepresentation. url;
[_ AssetLibrary assetForURL: url
ResultBlock: ^ (ALAsset * asset ){
If (asset ){
@ Synchronized (_ assets ){
[_ Assets addObject: asset];
If (_ assets. count = 1 ){
// Added first asset so reload data
// [Self. tableView into mselecw.mainthread: @ selector (reloadData) withObject: nil waitUntilDone: NO];
}
}
}
}
FailureBlock: ^ (NSError * error ){
NSLog (@ "operation was not successfull! ");
}];
}
}
};
ALAssetsLibraryAccessFailureBlock failureblock =
^ (NSError * myerror)
{
NSLog (@ "album Access failed =%@", [myerror localizedDescription]);
If ([myerror. localizedDescription rangeOfString: @ "Global denied access"]. location! = NSNotFound ){
NSLog (@ "unable to access the album. Please go to 'settings-> locate service' and set it to open .");
} Else {
NSLog (@ "album Access failed .");
}
};
// Process groups
Void (^ assetGroupEnumerator) (ALAssetsGroup *, BOOL *) = ^ (ALAssetsGroup * group, BOOL * stop ){
If (group! = Nil ){
NSString * g = [NSString stringWithFormat: @ "% @", group]; // gets the album group.
NSString * g1 = [g substringFromIndex: 16];
NSArray * arr = [[NSArray alloc] init];
Arr = [g1 componentsSeparatedByString: @ ","];
NSString * g2 = [[arr objectAtIndex: 0] substringFromIndex: 5];
If ([g2 isEqualToString: @ "Camera Roll"]) {
G2 = @ "camera film ";
}
If ([g2 isEqualToString: @ "MyPhoto"]) {
* Stop = NO;
[Group enumerateassetswitexceptions: NSEnumerationReverse usingBlock: assetEnumerator];
[AssetGroups addObject: group];
}
} Else {
NSLog (@ "********* else! ");
NSMutableArray * photos = [[NSMutableArray alloc] init];
NSMutableArray * thumbs = [[NSMutableArray alloc] init];
@ Synchronized (_ assets ){
NSMutableArray * copy = [_ assets copy];
For (ALAsset * asset in copy ){
[Photos addObject: [MWPhoto photoWithURL: asset. defaultRepresentation. url];
[Thumbs addObject: [MWPhoto photoWithImage: [UIImage imageWithCGImage: asset. thumbnail];
}
}
Self. photos = photos; // photo
Self. thumbs = thumbs; // thumbnail
}
};
// Process!
[Self. assetLibrary enumerateGroupsWithTypes: ALAssetsGroupAll
UsingBlock: assetGroupEnumerator
FailureBlock: failureblock];
});
}
Technical exchange field, job search->
Welcome to the Public Account: iOSDevTip [scan the following QR code directly]