https://github.com/wordpress-mobile/mediapicker-ios
WPMediaPicker is an iOS controller that allows capture and picking of media assets.
https://github.com/wordpress-mobile/mediapicker-ios
ios media photos video
Last synced: 11 months ago
JSON representation
WPMediaPicker is an iOS controller that allows capture and picking of media assets.
- Host: GitHub
- URL: https://github.com/wordpress-mobile/mediapicker-ios
- Owner: wordpress-mobile
- License: gpl-2.0
- Created: 2015-01-05T12:56:16.000Z (about 11 years ago)
- Default Branch: trunk
- Last Pushed: 2025-03-05T08:43:01.000Z (12 months ago)
- Last Synced: 2025-03-30T11:06:12.109Z (11 months ago)
- Topics: ios, media, photos, video
- Language: Objective-C
- Homepage:
- Size: 2.04 MB
- Stars: 110
- Watchers: 29
- Forks: 37
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# WPMediaPicker
[](http://cocoadocs.org/docsets/WPMediaPicker)
[](http://cocoadocs.org/docsets/WPMediaPicker)
[](http://cocoadocs.org/docsets/WPMediaPicker)
⚠️ **The WPMediaFramework was decommissioned on Nov 27, 2023, and is no longer maintained.**
WPMediaPicker is an iOS controller that allows capture and picking of media assets.
It allows:
* Allows selection of multiple media objects in one go.
* Capture of new media while inside the picker.
* Use different data sources for the media library.
* Switch between different albums.
* Filtering by media types.
* Preview of media (images and video) in full screen.
* Show the media picker inside as a keyboard input view.
* Super quick and memory optimized.
* Allows horizontal and vertical scroll of assets.
* Allows custom searching/filtering of assets.

## Installation
WPMediaPicker is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```
pod "WPMediaPicker"
```
## Usage
To use the picker do the following:
### Import header
```` objective-c
#import
````
### Create and present the picker in modal mode
```` objective-c
WPNavigationMediaPickerViewController * mediaPicker = [[WPNavigationMediaPickerViewController alloc] init];
mediaPicker.delegate = self;
[self presentViewController:mediaPicker animated:YES completion:nil];
````
### Implement didFinishPickingAssets delegate
The delegate is responsible for dismissing the picker when the operation completes. To dismiss the picker, call the [dismissViewControllerAnimated:completion:](https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/dismissViewControllerAnimated:completion:) method of the presenting controller responsible for displaying the `WPNavigationMediaPickerController` object. Please refer to the demo app.
```` objective-c
- (void)mediaPickerController:(WPMediaPickerViewController *)picker didFinishPickingAssets:(NSArray *)assets
{
[self dismissViewControllerAnimated:YES completion:nil];
}
````
### Other methods to display the picker
The example above shows the recommended way to show the picker in a modal. There are currently three available controllers to show the picker depending on your application needs:
* [WPMediaPickerViewController](Pod/Classes/WPMediaPickerViewController.h), this is the base collection view controller that displays the media. It can be used inside other view controllers using containment.
* [WPInputMediaPickerViewController](Pod/Classes/WPInputMediaPickerViewController.h), a wrapper of the WPMediaPickerController to be used as an inputView of an UIControl.
* [WPNavigationMediaPickerViewController](Pod/Classes/WPNavigationMediaPickerViewController.h), a convenience wrapper of the `WPMediaPickerViewController` inside a UINavigationController to show in a modal context.
### How to configure the appearance of the picker
Just use the standard appearance methods from UIKit. Here is an example how to configure the main components
```` objective-c
//Configure navigation bar background color
[[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[WPNavigationMediaPickerViewController class]]] setBarTintColor:[UIColor colorWithRed:0/255.0f green:135/255.0f blue:190/255.0f alpha:1.0f]];
//Configure navigation bar items text color
[[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[WPNavigationMediaPickerViewController class]]] setTintColor:[UIColor whiteColor]];
//Configure navigation bar title text color
[[UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[WPNavigationMediaPickerViewController class]]] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} ];
//Configure background color for media scroll view
[[UICollectionView appearanceWhenContainedInInstancesOfClasses:@[[WPMediaCollectionViewController class]]] setBackgroundColor:[UIColor colorWithRed:233/255.0f green:239/255.0f blue:243/255.0f alpha:1.0f]];
//Configure background color for media cell while loading image.
[[WPMediaCollectionViewCell appearanceWhenContainedInInstancesOfClasses:@[[WPMediaCollectionViewController class]]] setBackgroundColor:[UIColor colorWithRed:243/255.0f green:246/255.0f blue:248/255.0f alpha:1.0f]];
//Configure color for activity indicator while loading media collection
[[UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[WPMediaCollectionViewController class]]] setColor:[UIColor grayColor]];
````
### How to use a custom data source for the picker
If you have a custom database of media and you want to display it using the WPMediaPicker you need to implement the following protocols around your data:
* [WPMediaCollectionDataSource](Pod/Classes/WPMediaCollectionDataSource.h)
* [WPMediaGroup](Pod/Classes/WPMediaCollectionDataSource.h)
* [WPMediaAsset](Pod/Classes/WPMediaCollectionDataSource.h)
You can view the protocols documentation for more implementation details.
After you have implemented it you can use it by simple doing the following:
```` objective-c
self.customDataSource = [[WPCustomAssetDataSource alloc] init];
mediaPicker.dataSource = self.customDataSource;
````
### Sample Project
To run the example project, clone the repo, and run `pod install` from the `Example` directory first.
## Requirements
* ARC
* Photos, AVFoundation, ImageIO
* XCode 10 or above
* iOS 11 or above
## Contributing
Read our [Contributing Guide](CONTRIBUTING.md) to learn about reporting issues, contributing code, and more ways to contribute.
## Getting in Touch
If you have questions about getting setup or just want to say hi, join the [WordPress Slack](https://chat.wordpress.org) and drop a message on the `#mobile` channel.
## Author
WordPress, mobile@automattic.com
## License
WPMediaPicker is available under the GPL license. See the [LICENSE file](./LICENSE) for more info.