Capabilities 開啟Sandbox權限--轉載--https://juejin.cn/post/6844904199688290318
應用開發完成提交到App Store時,必須進行沙盒化。切換到工程target設置Tab的Capabilities中。
- 第一項就是App Sandbox開關,點擊ON,表示應用使用沙盒。
上圖的選項的一些解釋如下:
- Network:網絡訪問控制
Incoming Connections (Server): 應用做為Server對外提供HTTP,FTP等服務時需要打開。如果你的App擔任服務器角色,需要連接通信需要開啟此權限。Outgoing Connections (Client): 做為客戶端,訪問服務器時需要打開。如果你的App需要作為客戶端進行socket連接通信需要開啟此權限。
- Hardware:硬件資源控 它包含下面這些子項:
Camera: 如果你需要開啟攝像頭功能,勾選此項。Audio Input: 如果你需要獲取音頻 輸入權限(如麥克風),勾選此項。USB: 如果你需要使用USB傳輸文件,需要開啟此功能 4:Printing: 如果你需要打印文件里面的內容,需要開啟此功能
- App Data:獲取系統的聯系人,位置,日歷服務時需要打開
Contacts: 如果要訪問聯系人,需要勾選此項Location: 如果需要定位,需要勾選此項。Calendar: 如果需要訪問日歷,需要勾選此項。
- File Access:文件和用戶目錄的訪問控制,分為禁止
none,只讀,讀寫3類
User Selected File:文檔類應用或者需要用戶選擇打開某個文件時,需要選擇合適的訪問權限.Downloads Folder: 如果需要訪問當前用戶 Downloads文件夾,需要勾選此項,可以設置為只讀,或者可讀可寫Pictures Folder: 如果需要訪問當前用戶 Pictures文件夾,需要勾選此項,可以設置為只讀,或者可讀可寫Music Folder: 如果需要訪問當前用戶 Music文件夾,需要勾選此項,可以設置為只讀,或者可讀可寫Movies Folder: 如果需要訪問當前用戶 Movies文件夾,需要勾選此項,可以設置為只讀,或者可讀可寫
特別注意:如果應用中不需要的權限項,一律不要打開。否則App Review團隊會拒絕你的應用上架.
3.1.2 Entitlements 直接變xml,開啟Sandbox權限
實際上,在沙盒中每個需要訪問權限的項都對應一個key,對應的value,YES 或 NO表示是否允許訪問。當你選擇了項后,都會記錄在一個擴展名為.entitlements的plist 的文件中,如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<?
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
>com.apple.security.app-sandbox</
key
>
<
true
/>
<
key
>com.apple.security.assets.movies.read-write</
key
>
<
true
/>
<
key
>com.apple.security.assets.music.read-only</
key
>
<
true
/>
<
key
>com.apple.security.assets.pictures.read-only</
key
>
<
true
/>
<
key
>com.apple.security.cs.allow-dyld-environment-variables</
key
>
<
true
/>
<
key
>com.apple.security.cs.allow-jit</
key
>
<
true
/>
<
key
>com.apple.security.cs.allow-unsigned-executable-memory</
key
>
<
true
/>
<
key
>com.apple.security.cs.disable-executable-page-protection</
key
>
<
true
/>
<
key
>com.apple.security.cs.disable-library-validation</
key
>
<
true
/>
<
key
>com.apple.security.device.audio-input</
key
>
<
true
/>
<
key
>com.apple.security.device.camera</
key
>
<
true
/>
<
key
>com.apple.security.device.usb</
key
>
<
true
/>
<
key
>com.apple.security.files.bookmarks.app-scope</
key
>
<
true
/>
<
key
>com.apple.security.files.downloads.read-write</
key
>
<
true
/>
<
key
>com.apple.security.files.user-selected.read-write</
key
>
<
true
/>
<
key
>com.apple.security.network.client</
key
>
<
true
/>
<
key
>com.apple.security.network.server</
key
>
<
true
/>
<
key
>com.apple.security.personal-information.photos-library</
key
>
<
true
/>
<
key
>com.apple.security.print</
key
>
<
true
/>
<
key
>com.apple.security.temporary-exception.apple-events</
key
>
<
array
>
<
string
>com.apple.itunes</
string
>
</
array
>
<
key
>com.apple.security.temporary-exception.files.absolute-path.read-write</
key
>
<
true
/>
<
key
>com.apple.security.temporary-exception.shared-preference.read-only</
key
>
<
array
>
<
string
>com.apple.iphoto</
string
>
<
string
>com.apple.photobooth</
string
>
<
string
>com.apple.photos</
string
>
</
array
>
</
dict
>
</
plist
>
復制代碼
|
用plist屬性顯示如下:

應用打包時會對這個文件進行簽名。 當應用運行期間要獲取某個權限時,系統都會通過.entitlements去檢查應用是否有授權,如果沒有就拒絕訪問。
