Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
ru,
Expand Down Expand Up @@ -530,6 +531,7 @@
CODE_SIGN_ENTITLEMENTS = DBAttachmentPickerControllerExample/DBAttachmentPickerControllerExample.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DBAttachmentPickerControllerExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -546,6 +548,7 @@
CODE_SIGN_ENTITLEMENTS = DBAttachmentPickerControllerExample/DBAttachmentPickerControllerExample.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = DBAttachmentPickerControllerExample/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>DBAttachmentPickerControllerExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>DBAttachmentPickerControllerExample.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
4 changes: 4 additions & 0 deletions Example/DBAttachmentPickerControllerExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>This demo app uses your camera to take photos or videos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This demo app uses your Photo Library</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
6 changes: 3 additions & 3 deletions Source/DBAssetPickerController/DBAssetGroupsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ - (void)viewDidLoad {
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
self.fetchResults = @[smartAlbums, userAlbums];

[self updateAssetCollections];
}

Expand Down Expand Up @@ -104,13 +104,13 @@ - (void)updateAssetCollections {
for (NSNumber *assetCollectionSubtype in assetCollectionSubtypes) {
NSArray *collections = smartAlbums[assetCollectionSubtype];
for (PHAssetCollection *assetCollection in collections) {

PHFetchOptions *options = [PHFetchOptions new];
if (self.assetMediaType == PHAssetMediaTypeVideo || self.assetMediaType == PHAssetMediaTypeImage) {
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", self.assetMediaType];
}
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];

if (fetchResult.count) {
[assetCollections addObject:assetCollection];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ - (PHFetchResult *)assetsFetchResult {
if (_assetsFetchResult == nil) {
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
allPhotosOptions.fetchLimit = 50;

if (self.assetMediaType == PHAssetMediaTypeImage || self.assetMediaType == PHAssetMediaTypeVideo) {
allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %ld", self.assetMediaType];
Expand Down
5 changes: 5 additions & 0 deletions Source/DBAttachmentPickerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ typedef void (^CancelBlock)();
*/
@property (assign, nonatomic) BOOL allowsMultipleSelection; // default is NO

/*!
@brief Used to save photos or videos taken with the camera to camera roll
*/
@property (assign, nonatomic) BOOL saveToPhotoLibrary; // default is NO

/*!
@brief Creates and returns an attachment picker controller
@see presentOnViewController:
Expand Down
9 changes: 9 additions & 0 deletions Source/DBAttachmentPickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ + (instancetype)attachmentPickerControllerFinishPickingBlock:(FinishPickingBlock
controller.mediaType = DBAttachmentMediaTypeMaskAll;
controller.allowsSelectionFromOtherApps = NO;
controller.allowsMultipleSelection = NO;
controller.saveToPhotoLibrary = NO;
controller.capturedVideoQulity = UIImagePickerControllerQualityTypeMedium;

#pragma clang diagnostic push
Expand Down Expand Up @@ -105,6 +106,7 @@ + (instancetype)imagePickerControllerFinishPickingBlock:(FinishImagePickingBlock
DBAttachmentPickerController *controller = [self attachmentPickerControllerFinishPickingBlock:finishBlock cancelBlock:cancelBlock];
controller.mediaType = DBAttachmentMediaTypeImage;
controller.ignoreChangeMediaType = YES;
controller.saveToPhotoLibrary = NO;
return controller;
}

Expand All @@ -127,6 +129,7 @@ + (instancetype)videoPickerControllerFinishPickingBlock:(FinishVideoPickingBlock
DBAttachmentPickerController *controller = [self attachmentPickerControllerFinishPickingBlock:finishBlock cancelBlock:cancelBlock];
controller.mediaType = DBAttachmentMediaTypeVideo;
controller.ignoreChangeMediaType = YES;
controller.saveToPhotoLibrary = NO;
return controller;
}

Expand Down Expand Up @@ -330,12 +333,18 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking
UIImage *image = info[UIImagePickerControllerOriginalImage];
DBAttachment *attachment = [DBAttachment attachmentFromCameraImage:image];
attachmentArray = @[attachment];
if (self.saveToPhotoLibrary) {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}
} else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie] || [mediaType isEqualToString:(NSString *)kUTTypeVideo]) {
NSURL *documentURL = info[UIImagePickerControllerMediaURL];
if (documentURL) {
DBAttachment *attachment = [DBAttachment attachmentFromDocumentURL:documentURL];
attachmentArray = @[attachment];
}
if (self.saveToPhotoLibrary) {
UISaveVideoAtPathToSavedPhotosAlbum([documentURL path], nil, nil, nil);
}
}

__weak typeof(self) weakSelf = self;
Expand Down
10 changes: 8 additions & 2 deletions Source/Models/DBAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,18 @@ - (void)loadOriginalImageWithCompletion:(void(^)(UIImage *resultImage))completio
switch (self.sourceType) {
case DBAttachmentSourceTypePHAsset:
if (completion) {
PHImageRequestOptions *options = [PHImageRequestOptions new];
options.deliveryMode = PHVideoRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;

[[PHImageManager defaultManager] requestImageForAsset:self.photoAsset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:nil
options:options
resultHandler:^(UIImage *result, NSDictionary *info) {
completion(result);
if ([info[PHImageResultIsDegradedKey] isEqual:@(NO)]) {
completion(result);
}
}];
}
break;
Expand Down