简体   繁体   English

Xamarin iOS-每次我从Visual Studio运行时,用户生成的图像都会消失

[英]Xamarin iOS - User-generated images disappear every time I run from Visual Studio

So I have an app, in which users take photos. 因此,我有一个应用程序,用户可以在其中拍照。 I save these photos to the library and display them somewhere in the app. 我将这些照片保存到图库中,并将其显示在应用程序中的某个位置。 This all works great. 这一切都很好。 However, every time I run the app from Visual Studio (excluding the session when the photos are taken), these images don't show up. 但是,每次我从Visual Studio运行应用程序时(不包括拍照时的会话),这些图像都不会显示。

Launching the app from my device directly (so not in debugging mode) works as you would expect - I can see the images just fine. 直接从我的设备启动应用程序(因此不在调试模式下)可以正常工作-我可以看到图像。

I know there must be a way for this to work - the local database isn't wiped every time I run from Visual Studio for example - but I cannot for the life of me figure it out. 我知道必须有一种方法可以使它工作-例如,每次从Visual Studio运行时,不会擦除本地数据库-但我一生都无法解决。

I've tried saving the images elsewhere (Resources, Application Data, root MyDocuments, etc), but to no avail. 我尝试将图像保存到其他位置(资源,应用程序数据,根MyDocuments等),但无济于事。

Contents of GetImagePath(string filename) so you can see where I'm saving them: GetImagePath(string filename)内容,因此您可以看到将它们保存在哪里:

string libPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Library");
return Path.Combine(libPath, filename);

Anybody here got any ideas? 这里有人有想法吗? I think once the app is deployed it should be fine, but it's still damn annoying to have this happen whilst I'm developing. 我认为,一旦部署了该应用程序就可以了,但是在我开发过程中发生这种情况仍然令人讨厌。

Thanks in advance! 提前致谢!

EDIT: Here's my saving and loading code: Saving: NSData.FromArray(data).Save(path, true, out error) 编辑:这是我的保存和加载代码:保存: NSData.FromArray(data).Save(path, true, out error)

I'm displaying them like this: Content.Content = new Image { Source = filename } 我这样显示它们: Content.Content = new Image { Source = filename }

So, after a bit of playing around and stepping through code I've found the answer. 因此,在反复试验并逐步执行代码后,我找到了答案。

Your data in iOS is stored in an app container - the GUID associated with this container changes every time you build to the device. 您在iOS中的数据存储在应用容器中-每次您构建到设备时,与此容器关联的GUID都会更改。 As I was storing the full file path instead of just the filename, the images weren't showing up after a re-deploy because the full file path was looking for a no-longer-extant app container. 当我存储完整的文件路径而不仅仅是文件名时,重新部署后没有显示图像,因为完整的文件路径正在寻找不再存在的应用程序容器。 The contents of the Library and Documents folders are copied to the new app container each time - but using the full path from before the current version was build to the device wouldn't be able to find it. 每次将Library and Documents文件夹的内容复制到新的应用程序容器中-但无法使用从生成当前版本到设备的完整路径来查找它。

Switching to only store the filename and getting the full file path each time I need to show an image fixed this issue. 每次需要显示图像时,切换为仅存储文件名并获取完整的文件路径,即可解决此问题。

I noticed this issue during development, but in production there would have been issues where images weren't being found after an app update. 我在开发过程中注意到了这个问题,但在生产中会出现一些问题,即在应用程序更新后找不到图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin.IOS(使用 Rider):每次加载 XCode 或运行模拟器时,创建的图像集都会消失 - Xamarin.IOS (using Rider): created image sets disappear every time I load XCode or run simulator 如何在Visual Studio中的Xamarin iOS中每隔5分钟在后台运行任务 - How to run a task in background for every 5 minutes in xamarin ios in visual studio 从Visual Studio 2013运行xamarin.ios应用程序? - run xamarin.ios App from visual studio 2013? 我可以在iOS中为用户生成的优惠开单吗? - Can I bill in-app purchases for user-generated offers in iOS? 如何处理用户生成内容的 iOS 购买? - How to handle iOS purchases for user-generated content? Xamarin iOS:无法在Visual Studio 2017的控件上设置约束 - Xamarin iOS: Unable to set constraints on Controls from Visual Studio 2017 拦截来自 Visual Studio xamarin for mac / iOS 模拟器的 web 流量 - intercept web traffic from visual studio xamarin for mac / iOS simulator 从命令行构建Xamarin.IOS Visual Studio解决方案 - Building Xamarin.IOS Visual studio solution from command line 如何使用适用于iOS的Xamarin Studio(或MS Visual Studio for Xamarin)布局自动调整UI元素的大小? - How do I automatically size UI elements using Xamarin Studio (or MS Visual Studio for Xamarin) layout for iOS? iOS15,每次单击另一个列表的文本时,文本之间的链接都会消失 - iOS15, link between text is disappear every time when I click on another list’s text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM