Giter Club home page Giter Club logo

ctassetspickercontroller's Introduction

CTAssetsPickerController

CTAssetsPickerController is an iOS controller that allows picking multiple photos and videos from user's photo library. The usage and look-and-feel just similar to UIImagePickerController. It uses ARC and requires AssetsLibrary framework.

Screenshot

Features

  1. Picking multiple photos and videos from user's library.
  2. Filtering assets to pick only photos or videos.
  3. Limiting maximum number of assets to be picked.
  4. Average 5x fps.
  5. Conforming UIAccessibility Protocol.

Minimum Requirement

Xcode 5 and iOS 6.

Installation

via CocoaPods

Install CocoaPods if you do not have it:-

$ [sudo] gem install cocoapods
$ pod setup

Create Podfile:-

$ edit Podfile
platform :ios, '6.0'
pod 'CTAssetsPickerController',  '~> 1.0.3'
$ pod install

Use the Xcode workspace instead of the project from now on.

via Git Submodules

$ git submodule add http://github.com/chiunam/CTAssetsPickerController
  1. Drag CTAssetsPickerController folder in your project and add to your targets.
  2. Add AssetsLibrary.framework.

Usage

See the Demo Xcode project for details.

Import header

If using CocoaPods:-

#import <CTAssetsPickerController.h>

If using Submodules:-

#import "CTAssetsPickerController.h"

Create and present CTAssetsPickerController

CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
picker.delegate = self;
[self presentViewController:picker animated:YES completion:NULL];

Customization

You can set max number of selection to limit the assets to be picked.

picker.maximumNumberOfSelection = 10;

If you only want to pick photos or videos, create an ALAssetsFilter and assign to assetsFilter.

picker.assetsFilter = [ALAssetsFilter allPhotos]; // Only pick photos.

Hide the cancel button if you present the picker in UIPopoverController.

picker.showsCancelButton = NO;

Implement CTAssetsPickerControllerDelegate

didFinishPickingAssets

- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
// assets contains ALAsset objects.

didCancel (Optional)

- (void)assetsPickerControllerDidCancel:(CTAssetsPickerController *)picker;

Note

CTAssetsPickerController does not compress the picked photos and videos. You can process the picked assets via the defaultRepresentation property.

For example, you can create UIImage from picked assets like this:-

    ALAssetRepresentation *representation = alAsset.defaultRepresentation;
    
    UIImage *fullResolutionImage =
    [UIImage imageWithCGImage:representation.fullResolutionImage
                        scale:1.0f
                  orientation:(UIImageOrientation)representation.orientation];

and create NSData of picked vidoes:-

    ALAssetRepresentation *representation = alAsset.defaultRepresentation;
    
    NSURL *url          = representation.url;
    AVAsset *asset      = [AVURLAsset URLAssetWithURL:url options:nil];
    
    AVAssetExportSession *session =
    [AVAssetExportSession exportSessionWithAsset:asset presetName:AVAssetExportPresetLowQuality];
    
    session.outputFileType  = AVFileTypeQuickTimeMovie;
    session.outputURL       = VIDEO_EXPORTING_URL;
    
    [session exportAsynchronouslyWithCompletionHandler:^{
        
        if (session.status == AVAssetExportSessionStatusCompleted)
        {
            NSData *data    = [NSData dataWithContentsOfURL:session.outputURL];
        }
        
    }];

Please refer the documentation of ALAssetRepresentation and AVAssetExportSession.

License

The MIT License (MIT)

Copyright (c) 2013 Clement CN Tsang

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.

ctassetspickercontroller's People

Contributors

1and2papa avatar

Stargazers

Roman avatar

Watchers

Valaval avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.