dkahgld

UIImagePickerController+ST.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // UIImagePickerController+ST.m
  3. // STPhotoKit
  4. //
  5. // Created by 沈兆良 on 16/2/26.
  6. // Copyright © 2016年 沈兆良. All rights reserved.
  7. //
  8. #import "UIImagePickerController+ST.h"
  9. #import <MobileCoreServices/MobileCoreServices.h>
  10. #import <AVFoundation/AVFoundation.h>
  11. @implementation UIImagePickerController (ST)
  12. /**
  13. * 1.是否相册可用
  14. *
  15. * @return <#return value description#>
  16. */
  17. - (BOOL) isAvailablePhotoLibrary{
  18. return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
  19. }
  20. /**
  21. * 2.是否相机可用
  22. *
  23. * @return <#return value description#>
  24. */
  25. - (BOOL) isAvailableCamera{
  26. return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
  27. }
  28. /**
  29. * 3.是否可以保存相册可用
  30. *
  31. * @return <#return value description#>
  32. */
  33. - (BOOL) isAvailableSavedPhotosAlbum{
  34. return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
  35. }
  36. /**
  37. * 4.是否后置摄像头可用
  38. *
  39. * @return <#return value description#>
  40. */
  41. - (BOOL) isAvailableCameraDeviceRear{
  42. return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
  43. }
  44. /**
  45. * 5.是否前置摄像头可用
  46. *
  47. * @return <#return value description#>
  48. */
  49. - (BOOL)isAvailableCameraDeviceFront{
  50. return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
  51. }
  52. /**
  53. * 6.是否支持拍照权限
  54. *
  55. * @return <#return value description#>
  56. */
  57. - (BOOL) isSupportTakingPhotos{
  58. NSString *mediaType = AVMediaTypeVideo;
  59. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
  60. if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
  61. return NO;
  62. }else {
  63. return YES;
  64. }
  65. }
  66. /**
  67. * 7.是否支持获取相册视频权限
  68. *
  69. * @return <#return value description#>
  70. */
  71. - (BOOL)isSupportPickVideosFromPhotoLibrary{
  72. return [self isSupportsMedia:(__bridge NSString *)kUTTypeMovie
  73. sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  74. }
  75. /**
  76. * 8.是否支持获取相册图片权限
  77. *
  78. * @return <#return value description#>
  79. */
  80. - (BOOL) isSupportPickPhotosFromPhotoLibrary{
  81. return [self isSupportsMedia:(__bridge NSString *)kUTTypeImage
  82. sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  83. }
  84. - (BOOL)isSupportsMedia:(NSString *)mediaType sourceType:(UIImagePickerControllerSourceType)sourceType
  85. {
  86. __block BOOL result = NO;
  87. if ([mediaType length] == 0) {
  88. return NO;
  89. }
  90. NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
  91. [availableMediaTypes enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
  92. NSString *mediaType = (NSString *)obj;
  93. if ([mediaType isEqualToString:mediaType]){
  94. result = YES;
  95. *stop= YES;
  96. }
  97. }];
  98. return result;
  99. }
  100. + (UIImagePickerController *)imagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType{
  101. UIImagePickerController *controller = [[UIImagePickerController alloc]init];
  102. [controller setSourceType:sourceType];
  103. [controller setMediaTypes:@[(NSString *)kUTTypeImage]];
  104. return controller;
  105. }
  106. @end