#安卓
#ios
#unity/日常积累
如果是私有目录,例如要操作,unity对应,数据持久化路径,参考[[【Unity】数据持久化路径Application.persistentDataPath]],是不需要,额外的权限申请;
如果需要读写,公共目录,例如相册相关等路径,就需要额外申请,对应的权限
安卓的:
``` xml
```
如果没有权限,也可以尝试,通过代码,动态获取一下
``` java
if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
{
Permission.RequestUserPermission(Permission.ExternalStorageWrite);
// 需要处理异步授权结果
}
```
如果是ios的话,例如,如果要申请公共相册,相关的权限,就需要在Info.plist里面添加
``` xml
NSPhotoLibraryUsageDescription
需要访问相册来保存文件
```
unity后处理,参考[[xcode依赖处理 打包后处理通过podfile添加第三方库 PostProcessBuildClass]]
``` cs
///
/// 添加广告追踪权限
///
///
private static void AddInfoByTracking(string path)
{
string plistPath = Path.Combine(path, "Info.plist");
PlistDocument plist = new PlistDocument();
plist.ReadFromFile(plistPath);
PlistElementDict rootDict = plist.root;
// 添加广告追踪权限说明
rootDict.SetString("NSUserTrackingUsageDescription", "We need your consent to track advertisements to provide better services.");
// 添加定位服务权限说明
rootDict.SetString("NSLocationWhenInUseUsageDescription", "We need your location to provide personalized services.");
File.WriteAllText(plistPath, plist.WriteToString());
}
```