Unexpected results creating an album (group) on iOS8 using ALAssetsLibrary framework - ios

Apple is encouraging us to use the new PhotosFramework to interact with the camera roll in iOS8. But says nothing about AssetsLibraryFramework not working on iOS8.
So I'm using my pre-existing AssetsLibraryFramework code to do get the list of video ALAssets from the user's camera roll and display it. This works...still.
But when I try to create an album (group) using this AssetsLibraryFramework method:
- (void)addAssetsGroupAlbumWithName:(NSString *)name
resultBlock:(ALAssetsLibraryGroupResultBlock)resultBlock
failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock
Where resultBlock looks like this:
typedef void (^ALAssetsLibraryGroupResultBlock)(ALAssetsGroup *group));
The resultBlock is called with a nil group. The docs say that the group will be nil for a name collision, but there's no other album with the specified name. Definitely not a name collision.
I'm trying to determine if this is an error on my part, or evidence that ALAssetsLibrary cannot be trusted on iOS8 and I need to upgrade to PhotosFramework.
Are there other things that could cause the group to be nil? Is this method just not supported on iOS8?
Thanks in advance for any help.

Related

iOS - How to handle iPhone's photos whether changed when app become active?

I use a custom UICollectionView to display iPhone's photos. I want to reload UICollectionView when app become active after user delete/modify/add one or more photos.
I save PHAsset in a array, [previousAssetsArray isEqual:currentAssetsArray] is not working.
Any idea?
EDIT:
What is the NSObject isEqual: and hash default function?
When I get photos' assets again, its address changed, so previousAsset will not equal to currentAsset even they belong to a photo. [previousAsset isEqual: currentAsset] always NO.
I also use the property hash of PHAsset to check if photos changed. But I found when I just modified(crop) one photo in Photos app, its hash not changed.
try this [previousAssetsArray isEqualToArray:currentAssetsArray]
Example:: BOOL theyAreEqual = [myFirstArray isEqualToArray:mySecondArray];
if you want to compare count of both array
previousAssetsArray.count == currentAssetsArray .count

How to get BPM value from MPMediaItem class of ios?

I did lots of R&D on BPM but did not get any answer that resolve my issue. I am trying to get BPM value from MPmediaItem class of ios for my iphone application.I have to categorize my app users on the basis of beats per minute of their library songs. So my first task to find out BPM of songs. How can I do that? I got some answers like: 1.using MPMediaItemPropertyBeatsPerMinute property and 2. Use #"beatsPerMinutes" instaed of MPMediaItemPropertyBeatsPerMinute property of MPMediaItem class and also some more answer, but didnot get any success. It has always same result for all songs (return null for all songs). Do you have any sample code or logic to get this.
Thanks in advance.
Try this:
int BPM = [[mediaItem valueForProperty:MPMediaItemPropertyBeatsPerMinute]intValue];

Is it possible to retrieve photo by its name using predicate in Obj-C?

I wonder if it is possible to retrieve a photo from photo album using predicate in Obj-C with PHAsset Library?
I ask this question because I don't want to browse the entire album to retrieve only one photo.
Thanks.
What do you mean with "name"? You can filter photos/videos by the local identifier and other properties like width, height, mediaType. But there is no name or title property for a PHAsset.

Check PhotoLibrary if Image is already Exist

I am creating app to save images to Photo library from net. now i want to check every time before saving image to PhotoLibrary that image is already there or not?
i fetch the name of images stored in photo library but that name are different than original name so i don't know how to compare current image with already existing images!
please help me!
ALAssetsLibrary *Library=[[ALAssetsLibrary alloc]init];
NSMutableArray *arr_ImagesUrl=[[NSMutableArray alloc]init];
[Library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *Group,BOOL *stop){
[Group enumerateAssetsUsingBlock:^(ALAsset *asset,NSUInteger index,BOOL *stop)
{
NSLog(#"%#",[[asset defaultRepresentation]filename]);
}];
} failureBlock:^(NSError *error){NSLog(#"%#",error.description);}];
Basically theres is no such API in IOS documentation as far as I know.
What you can do, which is not quite the same as you originally wanted, is that in your application store an individual value (*) for every image the user selected throughout the app lifecycle. Based on this array of information you are able to tell whether a new selection is the same as a previous one. But still, you cannot do this for the full PhotoLibrary.
(*) This is an useful thread on SO which about detecting image similarity and/or creating a value (hash) which describes the image and usable for comparing images later.
My favourite is phash.
https://softwareengineering.stackexchange.com/questions/92830/how-to-know-if-two-images-are-the-same
or see this:
Compare two images to check if they are same

How do I access image data in Xcode iOS app developer?

I am VERY new to Xcode and even iOS apps/platform in general. I have a lot of image processing experience using other development platform environments and am looking to apply this toward iOS apps. I have noticed that nothing is mentioned for Xcode in regards to accessing image data and/or directly modifying it. Many people that have made tutorials seem to use an image picker but never have I seen where they say or show how to access the image data.
An answer to this would great. Guidance would be most appreciated. Thanks.
UIImage provides the ability to display images from several different formats, but it's immutable -- you can't change the data it uses and expect to see the image change. Instead, you'll get an image in one of the underlying types and work with that. You'll probably want to read up on both Core Graphics (Quartz) and Core Image. For example, you can use UIImage's -CGImage method to get the image as a CGImage and then use the Core Graphics CGImage...() functions to find out about the image data (format, bit depth, etc) and get the actual bits.
AVAssetLibrary can help you to modify image data.
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
[assetsLibrary assetForURL:photoUrl resultBlock:resultBlock
failureBlock:nil];
Using above code you will get asset of image in result block.
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *photoAsset)
{
ALAssetRepresentation *image_representation = [photoAsset defaultRepresentation];
//Do the stuff to get-modify image data from image_representation...
}
Hope this is what you are looking for.

Resources