0

I have let's say 5 text files in my Xamarin Forms iOS project under:

Project Name -> Resources -> TextFiles -> File1.txt, File2.txt, File3.txt, File4.txt, File5.txt

Upon launching my app I copy the files to a working folder via NSBundle.GetPathsForResources() from where I can start to use them.

public string GetWorkingFolder()
{
    string docs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

    return Path.Combine(docs, "..", "Library");
} 

For release I have decided I no longer need the last 3 files, so I removed them from the Project Name -> Resources -> TextFiles project folder.

This works fine when running the app on my iphone in debug mode, only File1.txt and File2.txt remain.

When I upload the app into App Connect though and deploy it through TestFlight on my device, the 5 files are still there.

I have tried the following:

  • deleted the files via my app in the working Library folder above
  • uninstalled the app
  • reinstalled the app

The 5 files return, which proves they are coming from the TestFlight package and not from a cached Library folder.

What is going on here? Even if the files were not deleted from the Library folder by myself, shouldn't uninstalling the app automatically remove those folders and files? How can I remove them from my package?

Any ideas?

jho
  • 199
  • 1
  • 8
  • 1
    have you cleaned your solution, and manually deleted the bin/obj folders before building? – Jason Oct 18 '22 at 18:34
  • Thanks for your reply Jason, I will try manually deleting these folders and report back on the outcome. – jho Oct 18 '22 at 19:14
  • I manually deleted those folders but the files are still being read from Resources. Can I confirm your understanding of the folder from my `GetWorkingFolder()` method above. Am I right to assume this folder and all its contents should be deleted everytime the app is uninstalled? – jho Oct 20 '22 at 16:42
  • yes, on iOS the folder should be deleted when you delete the app – Jason Oct 20 '22 at 16:44
  • Does that mean this could be a problem with TestFlight not properly tidying up between installs? – jho Oct 20 '22 at 16:56
  • That seems unlikely. I’d add some logic to check for the existence of the folder and any files when your app launches, and lo log each file it copies from Resources – Jason Oct 21 '22 at 08:56
  • I did more testing. I added a completely new file, let's say **File6.txt** directly to my Working Folder using the app during runtime, and not via compile time app Resources. I uninstalled the app, reinstalled it via TestFlight and **File6.txt** is still there. As such it does seem like the uninstall is not doing a proper cleanup job. – jho Oct 23 '22 at 17:34
  • Can you tell me the steps to "delete the files via my app in the working Library folder above"? Did you turn on iTunes backup? The library directory (except for the Caches subdirectory) is backed up by iTunes. For more details, you can check out the official documentation:https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system#application-directories – Zack Nov 02 '22 at 09:31
  • Hi Dongzhi, thanks for your reply. I simply used the .NET File.Delete on the filepath. I didn't consciously turn on iTunes backup. I don't know how to. I also did no backup or restore between uninstall and reinstall. But also if an application is deleted, wouldn't iTunes also delete related files in backup as well? – jho Nov 02 '22 at 15:41
  • Can you provide the relevant code where you use File.WriteAllText() and File.Delete()? You can check which directories your files are saved in and try to delete your backup file. Fore more details, you may refer to this official document:https://support.apple.com/en-sg/HT204215 – Zack Nov 03 '22 at 09:29
  • Dongzhi, thanks for your reply, but I'm going to put a hold on this for now, as at least I know on a fresh install on a new device only the files from `Project Name -> Resources -> TextFiles` will be included. That's good enough for now. If I need more answers I'll revive this thread. Cheers – jho Nov 16 '22 at 16:52

0 Answers0