I need to save file to library directory to support retry capability, but some users found it not working.
After some research, I got the following information:
- It affects about 100+ users per day, about one in ten thousand of DAU.
- 96% of them are iOS 13, others are iOS 9, iOS 10, iOS 12(App lowest support version is iOS9).
- Once it occurs, later file creations always failed.
- App cant save file to sandbox, including library document temp caches directory, using API [NSString writeToFile:atomically:encoding:error:],the error it returns is "{"localizedRecoveryOptions":"","localizedDescription":"The operation couldn’t be completed.","domain":"NSCocoaErrorDomain","code":512,"localizedFailureReason":"","userInfo":{"NSUserStringVariant":"Folder"},"localizedRecoverySuggestion":""}", The localizedDescription is in Chinese(because the phone locale is Chinese), but I cant type Chinese in the post.
- Users some have remaining iCloud storage space and some not. They all have remaining disk stroage space.
- The sandbox is not empty, it contains some other files that App creates, but the files cretaed date earlier than the user last reinstall date, may synchronized by iCloud, but the user charging via power, not PC.
- The files in sandbox that already exist(eg: sqlite datebase file) can be edited.
- Scanning sandbox directory attribute using api -[NSFileManager attributesOfItemAtPath:error:], directory write permission returns "NSFilePosixPermissions":493(755 in Octal).
- After reinstall the App, It can create files again, some users after some time(may one day or longer) it occurs agains, the old files come back, newly created files disappear. and other users no more problems.
So why this happned and how can I fix this problem?