Entry 6: A bit more technical


My last entry was about two possible candidates for in-app purchases. The first one I tackled was the option to remove photos from the iOS library. I think it would be a good idea to describe the code I wrote for it so far. Since iOS 8, working with assets is relatively simple.  In one of my previous posts, I mentioned that some of the Photo Pickers I tried were using deprecated libraries and I wanted to find (or write) something that would utilize the new Photo Library. It gave me flexibility to work with PHAssets later on.

The Picker I use returns photos selected by the user in a form of a PHAsset. In fact, it returns an array of PHAsset objects selected by the user. Each object holds all necessary information to perform action on an asset. I was able to use the PHPhotoLibrary and perform changes that would affect the main iOS library of photos and iCloud.  

Below is a piece of code I use to manipulate assets the user selected.The function is really simple and does all I want it to do. It access the main Photo library and attempts to delete assets from an array of PHAssets. It displays a popup to the user confirming the changes and if accepted, it deletes photos from the library. Once completed, it gives feedback about the result.

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

            [PHAssetChangeRequest deleteAssets:assetArray];

    } completionHandler:^(BOOL success, NSError *error) {
        NSLog(@"Finished Delete asset. %@", (success ? @"Success." : error));
        if (success) {
            NSLog(@"delete successfully");

The code explains "The Brain" of the functionality I'm gonna use. Of course, I still need to write the interface to enable/disable it and connect it with an in app purchase code. That should be fairly easy but I will deal with it later on. I would like to write more of the backend code so I can start modeling the interface based on features I have.

Time spent: 1 hours.

Total time spent on the project: 24 hours.