diff --git a/Example/DBAttachmentPickerControllerExample.xcodeproj/project.pbxproj b/Example/DBAttachmentPickerControllerExample.xcodeproj/project.pbxproj index eda8d60..f8dbff8 100644 --- a/Example/DBAttachmentPickerControllerExample.xcodeproj/project.pbxproj +++ b/Example/DBAttachmentPickerControllerExample.xcodeproj/project.pbxproj @@ -318,6 +318,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ru, @@ -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"; @@ -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"; diff --git a/Example/DBAttachmentPickerControllerExample.xcodeproj/project.xcworkspace/xcuserdata/gk.xcuserdatad/UserInterfaceState.xcuserstate b/Example/DBAttachmentPickerControllerExample.xcodeproj/project.xcworkspace/xcuserdata/gk.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..8f31071 Binary files /dev/null and b/Example/DBAttachmentPickerControllerExample.xcodeproj/project.xcworkspace/xcuserdata/gk.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Example/DBAttachmentPickerControllerExample.xcodeproj/xcuserdata/gk.xcuserdatad/xcschemes/xcschememanagement.plist b/Example/DBAttachmentPickerControllerExample.xcodeproj/xcuserdata/gk.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..88d8b88 --- /dev/null +++ b/Example/DBAttachmentPickerControllerExample.xcodeproj/xcuserdata/gk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,19 @@ + + + + + SchemeUserState + + DBAttachmentPickerControllerExample.xcscheme + + orderHint + 0 + + DBAttachmentPickerControllerExample.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Example/DBAttachmentPickerControllerExample/Info.plist b/Example/DBAttachmentPickerControllerExample/Info.plist index 7434562..e3fbd07 100644 --- a/Example/DBAttachmentPickerControllerExample/Info.plist +++ b/Example/DBAttachmentPickerControllerExample/Info.plist @@ -22,6 +22,10 @@ 1 LSRequiresIPhoneOS + NSCameraUsageDescription + This demo app uses your camera to take photos or videos + NSPhotoLibraryUsageDescription + This demo app uses your Photo Library UILaunchStoryboardName LaunchScreen UIMainStoryboardFile diff --git a/Source/DBAssetPickerController/DBAssetGroupsViewController.m b/Source/DBAssetPickerController/DBAssetGroupsViewController.m index b28ddb2..c5875ee 100644 --- a/Source/DBAssetPickerController/DBAssetGroupsViewController.m +++ b/Source/DBAssetPickerController/DBAssetGroupsViewController.m @@ -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]; } @@ -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]; } diff --git a/Source/DBAttachmentAlertController/DBAttachmentAlertController.m b/Source/DBAttachmentAlertController/DBAttachmentAlertController.m index 30097f7..41726d5 100644 --- a/Source/DBAttachmentAlertController/DBAttachmentAlertController.m +++ b/Source/DBAttachmentAlertController/DBAttachmentAlertController.m @@ -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]; diff --git a/Source/DBAttachmentPickerController.h b/Source/DBAttachmentPickerController.h index ef568c0..3813153 100644 --- a/Source/DBAttachmentPickerController.h +++ b/Source/DBAttachmentPickerController.h @@ -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: diff --git a/Source/DBAttachmentPickerController.m b/Source/DBAttachmentPickerController.m index 21ea6a1..cda6672 100644 --- a/Source/DBAttachmentPickerController.m +++ b/Source/DBAttachmentPickerController.m @@ -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 @@ -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; } @@ -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; } @@ -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; diff --git a/Source/Models/DBAttachment.m b/Source/Models/DBAttachment.m index dac69fd..2569603 100644 --- a/Source/Models/DBAttachment.m +++ b/Source/Models/DBAttachment.m @@ -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;