Reputation: 38641
When create a folder in iOS 15 operation system in flutter using this code:
Future<void> ensureInitialized() async {
if (!kIsWeb) {
final docDir = await getApplicationDocumentsDirectory();
dataDirectory = Directory('${docDir.parent.path}/biyiapp-dev');
if (!dataDirectory!.existsSync()) {
dataDirectory!.createSync(recursive: true);
}
File sessionFile = File('${dataDirectory!.path}/session.json');
if (sessionFile.existsSync()) {
final String jsonString = await sessionFile.readAsString();
lastSession = Session.fromJson(json.decode(jsonString));
}
}
}
when I run this code in real device of iPhone XR, shows error message like this:
[12:27:49:427] [ERROR] {"error":"FileSystemException: Creation failed, path = '/var/mobile/Containers/Data/Application/9024BC3C-CA76-42A5-977E-FCA9BA191FA5/biyiapp-dev' (OS Error: Operation not permitted, errno = 1)","message":"global error","stackTrace":"#0 _Directory.createSync (dart:io/directory_impl.dart:133)\n#1 ProAccount.ensureInitialized (package:pro_account/src/pro_account.dart:35)\n<asynchronous suspension>\n#2 DictGlobalConfig.loadApp.<anonymous closure> (package:biyi_app/config/dict_global_config.dart:22)\n<asynchronous suspension>\n"}
what should I do to make the flutter app could create folder in iOS real device by default?
Upvotes: 2
Views: 2160
Reputation: 1857
macOS needs you to request a specific entitlement in order to access the network. To do that open macos/Runner/DebugProfile.entitlements
and add the following key-value pair.
<key>com.apple.security.network.client</key>
<true/>
Then do the same thing in macos/Runner/Release.entitlements
.
check this.
Upvotes: 0