如果我需要从应用程序中写入或读取,我需要通知或从用户那里获得权限吗?



如果我需要从应用程序中写入或读取,我需要通知或获得用户的许可吗?

我需要知道官方和法律如果我必须要求用户授予我权限无论是ios或android

Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/counter.txt');
}
// Write the file
Future<File> writeCounter(int counter) async {
final file = await _localFile;
return file.writeAsString('$counter');
}

// Read the file
Future<int> readCounter() async {
try {
final file = await _localFile;
final contents = await file.readAsString();
return int.parse(contents);
} catch (e) {
return 0;
}
}turn int.parse(contents);
} catch (e) {
return 0;
}
}

是的,android需要读写权限,但iOS只需要读权限,例如:

我想要读写权限然后我会修改
info.plistiOS中的文件

<key>NSMicrophoneUsageDescription</key>
<string>This app require permission to access microphone</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app require permission to access gallery</string>
ask permission for whatever resources I want

AndroidMainfest.xmlandroid中的文件

<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

最新更新