Latest 0.0.1
Homepage https://github.com/tonyzonghui/WSAssetPickerController
License MIT Copyright (C) 2013 Zhang Zonghui

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Platforms ios 5, requires ARC
Frameworks QuartzCore, AssetsLibrary, UIKit, CoreGraphics
Authors

Note: This is a fork from w5mith/WSAssetPickerController. This version make changes to the image picker controller so that pre-selection is allowed (Some of the images in the image picker view are selected when they are shown).

You can use this version with cocoapods:

pod '[email protected]', '~>0.0.1'

Example:

WSAssetPickerController *assetPicker = [[WSAssetPickerController alloc] initWithDelegate:self];
assetPicker.selectedAssets = _selectedPhotos;
assetPicker.assetsLibrary = _assetLibrary;
[self presentViewController:assetPicker animated:YES completion:nil];

** We need to pass in an ALAssetLibrary instance and make sure that the instance is alive when we are referencing the ALAsset instances returned from the AssetPicker. ALAsset objects are no longer accessible when the ALAssetLibrary who is owning them get destroyed.

Description

This is an iOS, Objective-C alternative to UIImagePickerController that looks almost exactly the same, but provides the ability to select multiple images. It’s as easy to setup as UIImagePickerController and it works in both portrait and landscape orientations. It requires the addition of AssetsLibrary.framework. This code uses ARC.

Note: Using AssetsLibrary.framework will prompt users to allow use of their location data in order to access their photos.

Adding to your project

There are a few ways to add WSAssetPickerController to your project.

Option 1: Build and add the static library to your project:

  1. Open the demo project
  2. Select the WSAssetPickerCombined scheme
  3. In the menu bar choose Product > Build
  4. Copy the generated WSAssetPicker directory (found in the builds folder in the project directory) into your project.
  5. Make sure that libWSAssetPicker-Combined.a has been added to your targets Build Phases

Option 2:
Copy all the files in the src directory into your project and be sure ‘Copy items to destination group’s folder’ is checked

Option 3:
You can also get the code via CocoaPods (thanks @AlexIzvekov)

Use

  1. Import the header using #import "WSAssetPicker.h"
  2. Create an instance of WSAssetPickerController passing a delegate of type id <WSAssetPickerControllerDelegate>
  3. Present the WSAssetPickerController instance
  4. Implement the delegate methods
  5. You will also need to include the selection state png files: WSAssetViewSelectionIndicator.png and [email protected] or make your own.

Initialization and presentation

WSAssetPickerController *controller = [[WSAssetPickerController alloc] initWithDelegate:self];
[self presentViewController:controller animated:YES completion:NULL];

Delegate Methods


- (void)assetPickerControllerDidCancel:(WSAssetPickerController *)sender
{
    // Dismiss the WSAssetPickerController.
    [self dismissViewControllerAnimated:YES completion:NULL];
}

- (void)assetPickerController:(WSAssetPickerController *)sender didFinishPickingMediaWithAssets:(NSArray *)assets
{
    // Hang on to the picker to avoid ALAssetsLibrary from being released (see note below).
    self.picker = sender;

    // Dismiss the WSAssetPickerController.
    __block id weakSelf = self;
    [self dismissViewControllerAnimated:YES completion:^{

        // Do something with the assets here.

        // Release the picker.
        [weakSelf setPicker:nil];
    }];
}

Note: The ALAsset objects in the assets array are only valid while the ALAssetsLibrary instance they came from still exists.
(The ALAssetsLibrary is created in the picker controller implementation)

Latest podspec

{
    "name": "[email protected]",
    "version": "0.0.1",
    "summary": "This is an alternative to UIImagePickerController that allows multiple selection and pre-selection.",
    "description": "This is an iOS, Objective-C alternative to UIImagePickerController that looks almost exactly the same, but provides the ability to select multiple images. It's as easy to setup as UIImagePickerController and it works in both portrait and landscape orientations. It requires the addition of AssetsLibrary.framework. This code uses ARC.",
    "homepage": "https://github.com/tonyzonghui/WSAssetPickerController",
    "license": {
        "type": "MIT",
        "text": "               Copyright (C) 2013 Zhang Zonghuinn               Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:nn               The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.nn               THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.n               n"
    },
    "authors": {
        "Zhang Zonghui": "[email protected]"
    },
    "source": {
        "git": "https://github.com/tonyzonghui/WSAssetPickerController.git",
        "tag": "0.0.1"
    },
    "platforms": {
        "ios": 5
    },
    "source_files": "src/*.{h,m}",
    "frameworks": [
        "QuartzCore",
        "AssetsLibrary",
        "UIKit",
        "CoreGraphics"
    ],
    "requires_arc": true,
    "resources": [
        "demo/WSAssetViewSelectionIndicator.png",
        "demo/[email protected]"
    ],
    "prefix_header_file": "demo/WSAssetPickerController-Prefix.pch"
}

Pin It on Pinterest

Share This