Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit f6ded9d

Browse files
committed
Merge branch 'release/0.4.0'
2 parents fb034a5 + e8fc87a commit f6ded9d

24 files changed

+1641
-300
lines changed

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- WPMediaPicker (0.3.6)
2+
- WPMediaPicker (0.4.0)
33

44
DEPENDENCIES:
55
- WPMediaPicker (from `../`)
@@ -9,6 +9,6 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
WPMediaPicker: 2338901ebd4501e76103735ccc2e5e15ff1082ee
12+
WPMediaPicker: 1f349e117e9754f5ddc3c8ad3f9e59dae5df547a
1313

1414
COCOAPODS: 0.37.1

Example/WPMediaPicker.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; };
2323
DD821F4817504E75FB9E2B91 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9BA47A0718D787F4D3E328AF /* libPods-Tests.a */; };
2424
FFC3F6F31B0D9BB100EFC359 /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = FFC3F6F21B0D9BB100EFC359 /* Launch Screen.xib */; };
25+
FFE69A1D1B14AB840073C2EB /* OptionsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FFE69A1C1B14AB840073C2EB /* OptionsViewController.m */; };
2526
FFFFD8811A447E67000FC184 /* DemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FFFFD8801A447E67000FC184 /* DemoViewController.m */; };
2627
/* End PBXBuildFile section */
2728

@@ -63,6 +64,8 @@
6364
F0D09511821A352B062D5699 /* WPMediaPicker.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = WPMediaPicker.podspec; path = ../WPMediaPicker.podspec; sourceTree = "<group>"; };
6465
FBE1845B23E3060E3B0B5CF2 /* Pods-WPMediaPicker.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WPMediaPicker.release.xcconfig"; path = "Pods/Target Support Files/Pods-WPMediaPicker/Pods-WPMediaPicker.release.xcconfig"; sourceTree = "<group>"; };
6566
FFC3F6F21B0D9BB100EFC359 /* Launch Screen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "Launch Screen.xib"; sourceTree = "<group>"; };
67+
FFE69A1B1B14AB840073C2EB /* OptionsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionsViewController.h; sourceTree = "<group>"; };
68+
FFE69A1C1B14AB840073C2EB /* OptionsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OptionsViewController.m; sourceTree = "<group>"; };
6669
FFFFD87F1A447E67000FC184 /* DemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoViewController.h; sourceTree = "<group>"; };
6770
FFFFD8801A447E67000FC184 /* DemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoViewController.m; sourceTree = "<group>"; };
6871
/* End PBXFileReference section */
@@ -137,6 +140,8 @@
137140
6003F5A8195388D20070C39A /* Images.xcassets */,
138141
6003F594195388D20070C39A /* Supporting Files */,
139142
FFC3F6F21B0D9BB100EFC359 /* Launch Screen.xib */,
143+
FFE69A1B1B14AB840073C2EB /* OptionsViewController.h */,
144+
FFE69A1C1B14AB840073C2EB /* OptionsViewController.m */,
140145
);
141146
path = WPMediaPicker;
142147
sourceTree = "<group>";
@@ -360,6 +365,7 @@
360365
6003F59E195388D20070C39A /* AppDelegate.m in Sources */,
361366
FFFFD8811A447E67000FC184 /* DemoViewController.m in Sources */,
362367
6003F59A195388D20070C39A /* main.m in Sources */,
368+
FFE69A1D1B14AB840073C2EB /* OptionsViewController.m in Sources */,
363369
);
364370
runOnlyForDeploymentPostprocessing = 0;
365371
};
@@ -480,10 +486,14 @@
480486
buildSettings = {
481487
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
482488
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
489+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
490+
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
491+
CLANG_WARN_UNREACHABLE_CODE = YES;
483492
GCC_PRECOMPILE_PREFIX_HEADER = YES;
484493
GCC_PREFIX_HEADER = "WPMediaPicker/WPMediaPicker-Prefix.pch";
485494
INFOPLIST_FILE = "WPMediaPicker/WPMediaPicker-Info.plist";
486495
PRODUCT_NAME = "$(TARGET_NAME)";
496+
RUN_CLANG_STATIC_ANALYZER = YES;
487497
WRAPPER_EXTENSION = app;
488498
};
489499
name = Debug;
@@ -494,10 +504,14 @@
494504
buildSettings = {
495505
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
496506
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
507+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
508+
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
509+
CLANG_WARN_UNREACHABLE_CODE = YES;
497510
GCC_PRECOMPILE_PREFIX_HEADER = YES;
498511
GCC_PREFIX_HEADER = "WPMediaPicker/WPMediaPicker-Prefix.pch";
499512
INFOPLIST_FILE = "WPMediaPicker/WPMediaPicker-Info.plist";
500513
PRODUCT_NAME = "$(TARGET_NAME)";
514+
RUN_CLANG_STATIC_ANALYZER = YES;
501515
WRAPPER_EXTENSION = app;
502516
};
503517
name = Release;

Example/WPMediaPicker/AppDelegate.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#import "AppDelegate.h"
22
#import "DemoViewController.h"
3-
#import "WPMediaCollectionViewController.h"
3+
#import <WPMediaPicker/WPMediaPicker.h>
44

55
@implementation AppDelegate
66

@@ -17,6 +17,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
1717
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
1818
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} ];
1919
[[UICollectionView appearanceWhenContainedIn:[WPMediaCollectionViewController class],nil] setBackgroundColor:[UIColor colorWithRed:233/255.0f green:239/255.0f blue:243/255.0f alpha:1.0f]];
20+
[[WPMediaCollectionViewCell appearanceWhenContainedIn:[WPMediaCollectionViewController class],nil] setBackgroundColor:[UIColor colorWithRed:243/255.0f green:246/255.0f blue:248/255.0f alpha:1.0f]];
2021
return YES;
2122
}
2223

Example/WPMediaPicker/DemoViewController.m

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#import "DemoViewController.h"
2-
#import <WPMediaPicker/WPMediaPickerViewController.h>
2+
#import "WPPHAssetDataSource.h"
3+
#import "OptionsViewController.h"
4+
#import <WPMediaPicker/WPMediaPicker.h>
5+
#import <WPMediaPicker/WPMediaGroupTableViewCell.h>
6+
7+
@interface DemoViewController () <WPMediaPickerViewControllerDelegate, OptionsViewControllerDelegate>
38

4-
@interface DemoViewController () <WPMediaPickerViewControllerDelegate>
59
@property (nonatomic, strong) NSArray * assets;
610
@property (nonatomic, strong) NSDateFormatter * dateFormatter;
11+
@property (nonatomic, strong) id<WPMediaCollectionDataSource> customDataSource;
12+
@property (nonatomic, copy) NSDictionary *options;
13+
714
@end
815

916
@implementation DemoViewController
@@ -14,14 +21,21 @@ - (void)viewDidLoad
1421

1522
self.title = @"WPMediaPicker";
1623
//setup nav buttons
17-
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(clearSelection:)];
24+
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(showOptions:)];
1825

1926
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showPicker:)];
2027

2128
// date formatter
2229
self.dateFormatter = [[NSDateFormatter alloc] init];
2330
self.dateFormatter.dateStyle = NSDateFormatterMediumStyle;
2431
self.dateFormatter.timeStyle = NSDateFormatterMediumStyle;
32+
[self.tableView registerClass:[WPMediaGroupTableViewCell class] forCellReuseIdentifier:NSStringFromClass([WPMediaGroupTableViewCell class])];
33+
self.options = @{
34+
MediaPickerOptionsShowMostRecentFirst:@(NO),
35+
MediaPickerOptionsUsePhotosLibrary:@(NO),
36+
MediaPickerOptionsShowCameraCapture:@(YES)
37+
};
38+
2539
}
2640

2741
- (void)didReceiveMemoryWarning
@@ -44,19 +58,30 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
4458

4559
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
4660
{
47-
UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"];
61+
WPMediaGroupTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:NSStringFromClass([WPMediaGroupTableViewCell class]) forIndexPath:indexPath];
4862

49-
if (!cell){
50-
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
63+
id<WPMediaAsset> asset = self.assets[indexPath.row];
64+
__block WPMediaRequestID requestID = 0;
65+
requestID = [asset imageWithSize:CGSizeMake(100,100) completionHandler:^(UIImage *result, NSError *error) {
66+
if (error) {
67+
return;
68+
}
69+
if (cell.tag == requestID) {
70+
dispatch_async(dispatch_get_main_queue(), ^{
71+
cell.imagePosterView.image = result;
72+
});
73+
}
74+
}];
75+
cell.tag = requestID;
76+
cell.titleLabel.text = [self.dateFormatter stringFromDate:[asset date]];
77+
if ([asset assetType] == WPMediaTypeImage) {
78+
cell.countLabel.text = @"Image";
79+
} else if ([asset assetType] == WPMediaTypeVideo) {
80+
cell.countLabel.text = @"Video";
81+
} else {
82+
cell.countLabel.text = @"Other";
5183
}
5284

53-
ALAsset * asset = self.assets[indexPath.row];
54-
cell.imageView.image = [UIImage imageWithCGImage:[asset thumbnail]];
55-
56-
cell.textLabel.text = [self.dateFormatter stringFromDate:[asset valueForProperty:ALAssetPropertyDate]];
57-
cell.detailTextLabel.text = [asset valueForProperty:ALAssetPropertyType];
58-
cell.detailTextLabel.hidden = NO;
59-
6085
return cell;
6186
}
6287

@@ -86,9 +111,36 @@ - (void) clearSelection:(id) sender
86111

87112
- (void) showPicker:(id) sender
88113
{
89-
WPMediaPickerViewController * mediaPicker = [[WPMediaPickerViewController alloc] init];
114+
WPMediaPickerViewController *mediaPicker = [[WPMediaPickerViewController alloc] init];
90115
mediaPicker.delegate = self;
116+
mediaPicker.showMostRecentFirst = [self.options[MediaPickerOptionsShowMostRecentFirst] boolValue];
117+
if ([self.options[MediaPickerOptionsUsePhotosLibrary] boolValue]){
118+
self.customDataSource = [[WPPHAssetDataSource alloc] init];
119+
mediaPicker.dataSource = self.customDataSource;
120+
}
121+
mediaPicker.allowCaptureOfMedia = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
91122
[self presentViewController:mediaPicker animated:YES completion:nil];
92123
}
93124

125+
- (void) showOptions:(id) sender
126+
{
127+
OptionsViewController *optionsViewController = [[OptionsViewController alloc] init];
128+
optionsViewController.delegate = self;
129+
optionsViewController.options = self.options;
130+
[[self navigationController] pushViewController:optionsViewController animated:YES];
131+
}
132+
133+
#pragma - Options
134+
135+
- (void)optionsViewController:(OptionsViewController *)optionsViewController changed:(NSDictionary *)options
136+
{
137+
self.options = options;
138+
[self.navigationController popViewControllerAnimated:YES];
139+
}
140+
141+
- (void)cancelOptionsViewController:(OptionsViewController *)optionsViewController
142+
{
143+
[self.navigationController popViewControllerAnimated:YES];
144+
}
145+
94146
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import UIKit;
2+
3+
extern NSString const *MediaPickerOptionsShowMostRecentFirst;
4+
extern NSString const *MediaPickerOptionsUsePhotosLibrary;
5+
extern NSString const *MediaPickerOptionsShowCameraCapture;
6+
7+
@class OptionsViewController;
8+
9+
@protocol OptionsViewControllerDelegate <NSObject>
10+
11+
- (void)optionsViewController:(OptionsViewController *)optionsViewController changed:(NSDictionary *)options;
12+
13+
- (void)cancelOptionsViewController:(OptionsViewController *)optionsViewController;
14+
15+
@end
16+
@interface OptionsViewController : UITableViewController
17+
18+
@property (nonatomic, weak) id<OptionsViewControllerDelegate> delegate;
19+
@property (nonatomic, copy) NSDictionary *options;
20+
21+
@end
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#import "OptionsViewController.h"
2+
3+
NSString const *MediaPickerOptionsShowMostRecentFirst = @"MediaPickerOptionsShowMostRecentFirst";
4+
NSString const *MediaPickerOptionsUsePhotosLibrary = @"MediaPickerOptionsUsePhotosLibrary";
5+
NSString const *MediaPickerOptionsShowCameraCapture = @"MediaPickerOptionsShowCameraCapture";
6+
7+
8+
typedef NS_ENUM(NSInteger, OptionsViewControllerCell){
9+
OptionsViewControllerCellShowMostRecentFirst,
10+
OptionsViewControllerCellUsePhotosLibrary,
11+
OptionsViewControllerCellShowCameraCapture,
12+
OptionsViewControllerCellTotal
13+
};
14+
15+
@interface OptionsViewController ()
16+
17+
@property (nonatomic, strong) UITableViewCell *showMostRecentFirstCell;
18+
@property (nonatomic, strong) UITableViewCell *usePhotosLibraryCell;
19+
@property (nonatomic, strong) UITableViewCell *showCameraCaptureCell;
20+
21+
@end
22+
23+
@implementation OptionsViewController
24+
25+
- (void)viewDidLoad
26+
{
27+
[super viewDidLoad];
28+
29+
self.tableView.allowsSelection = NO;
30+
self.tableView.allowsMultipleSelection = NO;
31+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done:)];
32+
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel:)];
33+
34+
self.showMostRecentFirstCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell-1"];
35+
self.showMostRecentFirstCell.accessoryView = [[UISwitch alloc] init];
36+
((UISwitch *)self.showMostRecentFirstCell.accessoryView).on = [self.options[MediaPickerOptionsShowMostRecentFirst] boolValue];
37+
self.showMostRecentFirstCell.textLabel.text = @"Show Most Recent First";
38+
39+
self.usePhotosLibraryCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell-2"];
40+
self.usePhotosLibraryCell.accessoryView = [[UISwitch alloc] init];
41+
((UISwitch *)self.usePhotosLibraryCell.accessoryView).on = [self.options[MediaPickerOptionsUsePhotosLibrary] boolValue];
42+
self.usePhotosLibraryCell.textLabel.text = @"Use Photos Library (iOS 8 Only)";
43+
44+
self.showCameraCaptureCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell-3"];
45+
self.showCameraCaptureCell.accessoryView = [[UISwitch alloc] init];
46+
((UISwitch *)self.showCameraCaptureCell.accessoryView).on = [self.options[MediaPickerOptionsShowCameraCapture] boolValue];
47+
self.showCameraCaptureCell.textLabel.text = @"Show Capture Cell";
48+
}
49+
50+
#pragma mark - Table view data source
51+
52+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
53+
{
54+
return 1;
55+
}
56+
57+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
58+
{
59+
return OptionsViewControllerCellTotal;
60+
}
61+
62+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
63+
{
64+
switch (indexPath.row) {
65+
case OptionsViewControllerCellShowMostRecentFirst:
66+
return self.showMostRecentFirstCell;
67+
break;
68+
case OptionsViewControllerCellUsePhotosLibrary:
69+
return self.usePhotosLibraryCell;
70+
break;
71+
case OptionsViewControllerCellShowCameraCapture:
72+
return self.showCameraCaptureCell;
73+
break;
74+
default:
75+
break;
76+
}
77+
return nil;
78+
}
79+
80+
- (void) done:(id) sender
81+
{
82+
if ([self.delegate respondsToSelector:@selector(optionsViewController:changed:)]){
83+
id<OptionsViewControllerDelegate> delegate = self.delegate;
84+
NSDictionary *newOptions = @{
85+
MediaPickerOptionsShowMostRecentFirst:@(((UISwitch *)self.showMostRecentFirstCell.accessoryView).on),
86+
MediaPickerOptionsUsePhotosLibrary:@(((UISwitch *)self.usePhotosLibraryCell.accessoryView).on),
87+
MediaPickerOptionsShowCameraCapture:@(((UISwitch *)self.showCameraCaptureCell.accessoryView).on)
88+
};
89+
90+
[delegate optionsViewController:self changed:newOptions];
91+
}
92+
}
93+
94+
- (void) cancel:(id) sender
95+
{
96+
if ([self.delegate respondsToSelector:@selector(cancelOptionsViewController:)]){
97+
id<OptionsViewControllerDelegate> delegate = self.delegate;
98+
[delegate cancelOptionsViewController:self];
99+
}
100+
}
101+
102+
@end

Pod/Classes/WPALAssetDataSource.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@import Foundation;
2+
@import AssetsLibrary;
3+
#import "WPMediaCollectionDataSource.h"
4+
5+
/**
6+
An implementation of the WPDataSource protocol using the AssetsLibrary framework
7+
*/
8+
@interface WPALAssetDataSource : NSObject<WPMediaCollectionDataSource>
9+
10+
@end
11+
12+
/**
13+
An implementation of the WPMediaAsset protocol using the ALAsset class
14+
*/
15+
@interface ALAsset(WPMediaAsset)<WPMediaAsset>
16+
17+
@end
18+
19+
/**
20+
An implementation of the WPMediaGroup protocol using the ALAssetsGroup class
21+
*/
22+
@interface ALAssetsGroup(WPMediaGroup)<WPMediaGroup>
23+
24+
@end

0 commit comments

Comments
 (0)