简体   繁体   English

在 iOS 模拟器上通过 Xamarin.iOS 使用按需资源的问题

[英]Issue with using On-Demand Resource through Xamarin.iOS on iOS simulator

I have run into an issue where I am unable to access assets tagged for use in Apple's On-Demand Resource feature through a Xamarin.iOS app, but only when run on the simulator.我遇到了一个问题,我无法通过 Xamarin.iOS 应用程序访问标记为在 Apple 的按需资源功能中使用的资产,但只能在模拟器上运行时。 This only occurred after updating my environment.这仅在更新我的环境后发生。 I was previously on Visual Studio for Mac version 8.3.9 and Xcode version 11.2.1, and my app was able to access ODR resources without issue on both simulator and physical device.我之前使用的是 Visual Studio for Mac 版本 8.3.9 和 Xcode 版本 11.2.1,我的应用程序能够在模拟器和物理设备上访问 ODR 资源而没有问题。

Now I am on Visual Studio version 8.4.2 and Xcode version 11.3.1, and my app is not functioning correctly.现在我使用的是 Visual Studio 8.4.2 版和 Xcode 11.3.1 版,但我的应用程序无法正常运行。 However, I am only seeing issues when running on an iOS simulator (for any iOS version).但是,我只在 iOS 模拟器上运行时才看到问题(对于任何 iOS 版本)。 I can build and run on a physical device (running iOS version 13.0)and am seeing no problems.我可以在物理设备(运行 iOS 13.0 版)上构建和运行,并且没有发现任何问题。

I am creating and tagging an asset for use in Apple ODR through Visual Studio for Mac.我正在通过 Visual Studio for Mac 创建和标记要在 Apple ODR 中使用的资产。 I have a ZIP file that I add into my app's iOS project directly as a resource.我有一个 ZIP 文件,可以直接作为资源添加到我的应用程序的 iOS 项目中。 In its properties, I set the BuildAction as BundleResource, select “Do Not Copy” to output directory, and give it an On-Demand Resource tag.在它的属性中,我将 BuildAction 设置为 BundleResource,选择“Do Not Copy”到输出目录,并给它一个 On-Demand Resource 标签。

When I build my solution, I can see this ZIP file nested in a *.assetpack directory under bin/iPhone/Debug/device-builds/iphone12.3-13.0/OnDemandResources .当我构建我的解决方案时,我可以看到这个 ZIP 文件嵌套在bin/iPhone/Debug/device-builds/iphone12.3-13.0/OnDemandResources下的 *.assetpack 目录中。 I believe it is supposed to be put in bin/iPhone/Debug/OnDemandResources/ instead.我相信它应该放在bin/iPhone/Debug/OnDemandResources/ When I run the code that calls NSBundleResourceRequest 's BeginAccessingResourcesAsync , it seemingly does nothing.当我运行调用NSBundleResourceRequestBeginAccessingResourcesAsync的代码时,它似乎什么也没做。 I see the following error message in the Application Output debug window in VS after that function is called:调用该函数后,我在 VS 的应用程序输出调试窗口中看到以下错误消息:

Begin: Request 0x0x600002566100 response: Error: Error Domain=NSCocoaErrorDomain Code=4994 "The requested application data doesn’t exist." UserInfo={NSLocalizedFailureReason=InvalidTag}

There's no other error or exception being thrown.没有抛出其他错误或异常。 When I try to get the resource path from the NSBundleResourceRequest.Bundle object, it expectedly returns null.当我尝试从NSBundleResourceRequest.Bundle对象获取资源路径时,它预期返回 null。

Any reason why this is happening, and why this is only occurring on the iOS simulator and not on a physical device?发生这种情况的任何原因,以及为什么这只发生在 iOS 模拟器上而不是在物理设备上? I haven't been able to find anything useful when searching for the above error message.搜索上述错误消息时,我找不到任何有用的信息。 Did something change in Visual Studio regarding how bundled assets are built in Debug mode?关于如何在调试模式下构建捆绑资产,Visual Studio 中是否发生了一些变化?

Not really an answer, but more of a workaround.不是真正的答案,而是更多的解决方法。 Using version 8.3.9 of VS for Mac seems to not throw this error, so I reverted back to that version使用 VS for Mac 8.3.9 版本似乎不会抛出此错误,因此我恢复到该版本

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM