文章目錄
一、權限說明
關於這兩個權限,沒有看到 Apple 給開發者的具體建議。
根據:https://support.apple.com/zh-cn/guide/mac-help/mh32356/mac,對於用戶而言,這兩個權限是
完全磁盤訪問權限 : 顯示可以訪問電腦上所有文件的 App,包括其他 App(例如“郵件”、“信息”、Safari 瀏覽器和“家庭”)中的數據、時間機器備份中的數據以及此 Mac 上所有用戶的部分管理設置。
文件和文件夾 :顯示可以訪問此 Mac 上不同位置的文件和文件夾的 App。如果您想要阻止其訪問文件和文件夾,請取消選擇該 App。
相關 url 跳轉:
/*
Privacy_AllFiles 完全磁盤訪問權限
Privacy_Assistive 文件和文件夾
*/
NSString *urlString = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Assistive";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:urlString]];
二、文件和文件夾
權限
1、需要授權的目錄
參考自:https://nektony.com/duplicate-finder-free/folders-permission
文件和文件夾
權限,主要針對下面幾個文件夾(有其他文件夾希望告知):
- Desttop Folder 桌面文件夾,
~/Desktop
- Documents Folder "文稿"文件夾,
~/Documents
- Downloads Foder 下載文件夾,
~/Downloads
- Removable Volumes 可移除的宗卷(如 U 盤), 如
/Volumes/SSWD
- Network Volumes 服務器卷宗
2、授權動作
在SIP 開啓狀態下,應用訪問上述文件夾時,將會彈出窗口提示用戶授權:
授權結果將會顯示在 系統偏好設置
--> 安全性與隱私
--> 隱私
--> 文件和文件夾
中。
3、不需要授權的目錄
由於不明確具體哪些目錄需要授權,所以測試了以下目錄,他們均不需要 文件和文件夾 或 完全磁盤訪問權限
/Applications
~
~/Library
~/Library/Containers
~/Library/WebKit
~/Library/QuickTime
可以讀到數據~/Pictures
~/Music
~/Library/Mobile Documents
~/Library/Mobile\ Documents/com\~apple\~ScriptEditor2/Documents
三、完全磁盤訪問權限
1、手動增刪
可以在偏好設置面板中,手動添加和刪除應用。
點擊添加,會打開文件夾,來選擇。
2、和 文件和文件夾 權限相關
擁有完全磁盤訪問權限,在文件和文件夾 中,也會顯示出來。
已經授權,完全磁盤訪問權限,則訪問 桌面等,不會再繼續要求授權。
3、SIP 下 無法用命令 完全磁盤訪問 權限
1)
tccutil reset all com.ms.VideoEditDemo
2)
$ tccutil reset AllFiles
tccutil: Failed to reset database
$ tccutil reset Assistive
tccutil: Failed to reset database
以上命令均無法像 移除麥克風權限一樣移除 完全磁盤訪問權限 和 文件夾權限。手動移除是最好的方式。
非 SIP 待測試。
4、完全磁盤訪問權限 的授權判斷
provided by @HsiangHo
typedef NS_ENUM(NSUInteger, FDAAuthorizationStatus) {
FDAAuthorizationStatusNotDetermined = 0,
FDAAuthorizationStatusDenied,
FDAAuthorizationStatusAuthorized
} NS_SWIFT_NAME(AuthorizationStatus);
NS_ASSUME_NONNULL_BEGIN
@interface FullDiskAccessAuthorizer : NSObject
+ (instancetype)sharedInstance;
- (FDAAuthorizationStatus)authorizationStatus;
- (void)requestAuthorization;
@end
#import "FullDiskAccessAuthorizer.h"
#import <pwd.h>
#import <Cocoa/Cocoa.h>
static FullDiskAccessAuthorizer *instance;
@implementation FullDiskAccessAuthorizer
+ (instancetype)sharedInstance {
@synchronized (self) {
if(nil == instance) {
instance = [[FullDiskAccessAuthorizer alloc] init];
}
return instance;
}
}
- (FDAAuthorizationStatus)authorizationStatus {
NSString *userHomePath = NSHomeDirectory();
BOOL isSandboxed = (nil != NSProcessInfo.processInfo.environment[@"APP_SANDBOX_CONTAINER_ID"]);
NSLog(@"isSandboxed : %d",isSandboxed);
if (isSandboxed)
{
struct passwd *pw = getpwuid(getuid());
assert(pw);
userHomePath = [NSString stringWithUTF8String:pw->pw_dir];
}
NSString *path = [userHomePath stringByAppendingPathComponent:@"Library/Safari"];
NSLog(@"userHomePath : %@, path : %@",userHomePath,path);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
NSArray<NSString *> *paths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
NSLog(@"paths : %@",paths);
if (paths == nil && fileExists){
return FDAAuthorizationStatusDenied;
} else if (fileExists) {
return FDAAuthorizationStatusAuthorized;
} else {
return FDAAuthorizationStatusNotDetermined;
}
}
- (void)requestAuthorization {
if (@available(macOS 10.14, *)){
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"x-apple.systempreferences:com.apple.preference.security?Privacy_AllFiles"]];
}
}
@end
伊織 2020-02-10(一)願患者早日康復