Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增iOS14下可以添加访问更多照片 #1526

Merged
merged 5 commits into from
Mar 2, 2022
Merged
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
20 changes: 20 additions & 0 deletions TZImagePickerController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
570A348C26D7275C000EEF2E /* Photos.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570A348B26D7275C000EEF2E /* Photos.framework */; };
570A348E26D72762000EEF2E /* PhotosUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570A348D26D72762000EEF2E /* PhotosUI.framework */; };
570A349026D72768000EEF2E /* PhotosUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 570A348F26D72768000EEF2E /* PhotosUI.framework */; };
57DD378A26D61592005090FF /* TZAuthLimitedFooterTipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 57DD378926D61592005090FF /* TZAuthLimitedFooterTipView.m */; };
57DD378E26D619C9005090FF /* TZAuthLimitedFooterTipView.m in Sources */ = {isa = PBXBuildFile; fileRef = 57DD378926D61592005090FF /* TZAuthLimitedFooterTipView.m */; };
6D32B9BD1CD83640005CE1E0 /* LxGridViewFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D32B9BC1CD83640005CE1E0 /* LxGridViewFlowLayout.m */; };
6D4608311DFFC60D004FB009 /* TZGifPhotoPreviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D4608301DFFC60D004FB009 /* TZGifPhotoPreviewController.m */; };
6D5358CD1D64600F00928CC6 /* NSBundle+TZImagePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 6D5358CC1D64600F00928CC6 /* NSBundle+TZImagePicker.m */; };
Expand Down Expand Up @@ -117,6 +122,11 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
570A348B26D7275C000EEF2E /* Photos.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Photos.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Photos.framework; sourceTree = DEVELOPER_DIR; };
570A348D26D72762000EEF2E /* PhotosUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PhotosUI.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/iOSSupport/System/Library/Frameworks/PhotosUI.framework; sourceTree = DEVELOPER_DIR; };
570A348F26D72768000EEF2E /* PhotosUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PhotosUI.framework; path = System/Library/Frameworks/PhotosUI.framework; sourceTree = SDKROOT; };
57DD378826D61592005090FF /* TZAuthLimitedFooterTipView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TZAuthLimitedFooterTipView.h; sourceTree = "<group>"; };
57DD378926D61592005090FF /* TZAuthLimitedFooterTipView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TZAuthLimitedFooterTipView.m; sourceTree = "<group>"; };
6D12FC191D66B71E00182C44 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
6D12FC1A1D66B71E00182C44 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
6D32B9BB1CD83640005CE1E0 /* LxGridViewFlowLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LxGridViewFlowLayout.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -197,6 +207,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
570A349026D72768000EEF2E /* PhotosUI.framework in Frameworks */,
903996931F447604005E77C2 /* Photos.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -219,6 +230,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
570A348E26D72762000EEF2E /* PhotosUI.framework in Frameworks */,
570A348C26D7275C000EEF2E /* Photos.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -334,6 +347,8 @@
B662C36E2662914D006A672A /* TZVideoEditedPreviewController.m */,
6DD050291DF659ED0057C78D /* TZProgressView.h */,
6DD0502A1DF659ED0057C78D /* TZProgressView.m */,
57DD378826D61592005090FF /* TZAuthLimitedFooterTipView.h */,
57DD378926D61592005090FF /* TZAuthLimitedFooterTipView.m */,
90CE84AC1C3A89EF003D0779 /* TZImageManager.h */,
90CE84AD1C3A89EF003D0779 /* TZImageManager.m */,
901CC3F821CB757500C55443 /* TZImageRequestOperation.h */,
Expand Down Expand Up @@ -365,6 +380,9 @@
903996911F447603005E77C2 /* Frameworks */ = {
isa = PBXGroup;
children = (
570A348D26D72762000EEF2E /* PhotosUI.framework */,
570A348F26D72768000EEF2E /* PhotosUI.framework */,
570A348B26D7275C000EEF2E /* Photos.framework */,
903996941F447609005E77C2 /* AssetsLibrary.framework */,
903996921F447604005E77C2 /* Photos.framework */,
);
Expand Down Expand Up @@ -593,6 +611,7 @@
900EF0021C2BD7E400EA709B /* TZAssetCell.m in Sources */,
6DD0502B1DF659ED0057C78D /* TZProgressView.m in Sources */,
6D32B9BD1CD83640005CE1E0 /* LxGridViewFlowLayout.m in Sources */,
57DD378A26D61592005090FF /* TZAuthLimitedFooterTipView.m in Sources */,
6D4608311DFFC60D004FB009 /* TZGifPhotoPreviewController.m in Sources */,
900EF0161C2C134900EA709B /* TZPhotoPreviewCell.m in Sources */,
900E65871C2BB8D5003D9A9E /* ViewController.m in Sources */,
Expand Down Expand Up @@ -633,6 +652,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
57DD378E26D619C9005090FF /* TZAuthLimitedFooterTipView.m in Sources */,
B662C37326629179006A672A /* TZVideoEditedPreviewController.m in Sources */,
B6977B0A265FDB280028BA31 /* TZVideoCropController.m in Sources */,
901CC3FB21CB757500C55443 /* TZImageRequestOperation.m in Sources */,
Expand Down
12 changes: 7 additions & 5 deletions TZImagePickerController/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="14F1509" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,9 +16,9 @@
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
Expand Down
2 changes: 2 additions & 0 deletions TZImagePickerController/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>访问相机以拍照</string>
<key>NSLocationUsageDescription</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// TZAuthLimitedFooterTipView.h
// TZImagePickerController
//
// Created by qiaoxy on 2021/8/24.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface TZAuthLimitedFooterTipView : UIView

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// TZAuthLimitedFooterTipView.m
// TZImagePickerController
//
// Created by qiaoxy on 2021/8/24.
//

#import "TZAuthLimitedFooterTipView.h"
#import "TZImagePickerController.h"

@interface TZAuthLimitedFooterTipView()
@property (nonatomic,strong) UIImageView *tipImgView;
@property (nonatomic,strong) UILabel *tipLable;
@property (nonatomic,strong) UIImageView *detailImgView;
@end

@implementation TZAuthLimitedFooterTipView

- (instancetype)init {
self = [super init];
if (self) {
[self initSubViews];
}
return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
}
return self;
}

- (void)initSubViews {
[self addSubview:self.tipImgView];
[self addSubview:self.tipLable];
[self addSubview:self.detailImgView];
CGFloat margin = 15;
CGFloat tipImgViewWH = 20;
CGFloat detailImgViewWH = 12;
CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

self.tipImgView.frame = CGRectMake(margin, 0, tipImgViewWH, tipImgViewWH);
self.detailImgView.frame = CGRectMake(screenW - margin - detailImgViewWH, 0, detailImgViewWH, detailImgViewWH);

CGFloat tipLabelX = CGRectGetMaxX(self.tipImgView.frame) + 10;
CGFloat tipLabelW = screenW - tipLabelX - detailImgViewWH - margin - 4;
self.tipLable.frame = CGRectMake(tipLabelX, 0, tipLabelW, self.bounds.size.height);

self.tipImgView.center = CGPointMake(self.tipImgView.center.x, self.tipLable.center.y);
self.detailImgView.center = CGPointMake(self.detailImgView.center.x, self.tipLable.center.y);
}

#pragma mark - Getter

- (UIImageView *)tipImgView {
if (!_tipImgView) {
_tipImgView = [[UIImageView alloc] init];
_tipImgView.contentMode = UIViewContentModeScaleAspectFit;
_tipImgView.image = [UIImage tz_imageNamedFromMyBundle:@"tip"];
}
return _tipImgView;
}

- (UILabel *)tipLable {
if (!_tipLable) {
_tipLable = [[UILabel alloc] init];
NSString *appName = [TZCommonTools tz_getAppName];
_tipLable.text = [NSString stringWithFormat:@"你已设置%@只能访问相册部分照片,建议允许访问「所有照片」",appName];
_tipLable.numberOfLines = 0;
_tipLable.font = [UIFont systemFontOfSize:14];
_tipLable.textColor = [UIColor colorWithRed:0.40 green:0.40 blue:0.40 alpha:1.0];
}
return _tipLable;
}

- (UIImageView *)detailImgView {
if (!_detailImgView) {
_detailImgView = [[UIImageView alloc] init];
_detailImgView.contentMode = UIViewContentModeScaleAspectFit;
_detailImgView.image = [UIImage tz_imageNamedFromMyBundle:@"right_arrow"];
}
return _detailImgView;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
/// Return YES if Authorized 返回YES如果得到了授权
- (BOOL)authorizationStatusAuthorized;
- (void)requestAuthorizationWithCompletion:(void (^)(void))completion;
- (BOOL)isPHAuthorizationStatusLimited;

/// Get Album 获得相册/相册数组
- (void)getCameraRollAlbumWithFetchAssets:(BOOL)needFetchAssets completion:(void (^)(TZAlbumModel *model))completion;
Expand Down
10 changes: 10 additions & 0 deletions TZImagePickerController/TZImagePickerController/TZImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ - (void)configTZScreenWidth {
}
}

- (BOOL)isPHAuthorizationStatusLimited {
if (@available(iOS 14,*)) {
NSInteger status = [PHPhotoLibrary authorizationStatusForAccessLevel:PHAccessLevelReadWrite];
if (status == PHAuthorizationStatusLimited) {
return YES;
}
}
return NO;
}

/// Return YES if Authorized 返回YES如果得到了授权
- (BOOL)authorizationStatusAuthorized {
if (self.isPreviewNetworkImage) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
@property (nonatomic, copy) NSString *photoPreviewOriginDefImageName __attribute__((deprecated("Use -photoPreviewOriginDefImage.")));
@property (nonatomic, copy) NSString *photoNumberIconImageName __attribute__((deprecated("Use -photoNumberIconImage.")));
@property (nonatomic, strong) UIImage *takePictureImage;
@property (nonatomic, strong) UIImage *addMorePhotoImage;
@property (nonatomic, strong) UIImage *photoSelImage;
@property (nonatomic, strong) UIImage *photoDefImage;
@property (nonatomic, strong) UIImage *photoOriginSelImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ - (void)configDefaultImageName {
self.photoPreviewOriginDefImageName = @"preview_original_def";
self.photoOriginDefImageName = @"photo_original_def";
self.photoOriginSelImageName = @"photo_original_sel";
self.addMorePhotoImage = [UIImage tz_imageNamedFromMyBundle:@"addMore"];
}

- (void)setTakePictureImageName:(NSString *)takePictureImageName {
Expand Down
Loading