Don't parse the ALAsset
description string! If the description ever changes your code breaks. Use the methods ALAsset
and NSURL
provide you. First, get the dictionary of URLs (mapped by asset type) through the valueForProperty:
method. Then, for each URL, get the absoluteString
and remove the query string from it. I got the string you were looking for by placing the following code in the application:didFinishLaunchingWithOptions:
method from the single-view iPhone app template.
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) {
NSDictionary *URLDictionary = [asset valueForProperty:ALAssetPropertyURLs];
for (NSURL *URL in [URLDictionary allValues]) {
NSString *URLString = [URL absoluteString];
NSString *query = [URL query];
if ([query length] > 0) {
NSString *toRemove = [NSString stringWithFormat:@"?%@",query];
URLString = [URLString stringByReplacingOccurrencesOfString:toRemove withString:@""];
NSLog(@"URLString = %@", URLString);
}
}
}];
} failureBlock:^(NSError *error) {
}];