Xamarin.forms Xamarin表格(VS2019)和#x2B;iOS意图UI:如何从扩展访问资产(IntentsUI)

Xamarin.forms Xamarin表格(VS2019)和#x2B;iOS意图UI:如何从扩展访问资产(IntentsUI),xamarin.forms,xamarin.ios,sirishortcuts,Xamarin.forms,Xamarin.ios,Sirishortcuts,我使用Xamarin版本的用于Siri目的。我可以通过请求bundle by identifier(使用主应用程序的BundleIdentifier)从SoupChefIntentsUI.IntentViewController访问容器的资产,然后通过传递bundle来加载图像 CGSize DisplayOrderConfirmation(Order order, OrderSoupIntent intent, OrderSoupIntentResponse response){ /* unr

我使用Xamarin版本的用于Siri目的。我可以通过请求bundle by identifier(使用主应用程序的BundleIdentifier)从SoupChefIntentsUI.IntentViewController访问容器的资产,然后通过传递bundle来加载图像

CGSize DisplayOrderConfirmation(Order order, OrderSoupIntent intent, OrderSoupIntentResponse response){
/* unrelated code */

//this line work in the SoupChef example but
//On Xamarin.Forms this returns null
var containerBundle = NSBundle.FromIdentifier("com.something.SoupChef");

//always returns null because it seems it looks into the IntentsUI.Assets
var iconNull = UIImage.FromBundle("AppIcon");

//it returns the icon from the SoupChef.Assets
var iconNotNull = UIImage.FromBundle("AppIcon", containerBundle, configuration: null);

/* unrelated code */
}
我还可以通过如下方式创建NSBundle来检索AppIcon(以防您不想假设捆绑标识名称不符合Apple标准,其中容器和扩展具有相同的捆绑标识,但最后一段除外)

我的问题是,我想在另一个使用Xamarin.Forms的项目上做同样的事情,而在SoupChef项目上对我有用的前两种方法在这里不起作用

有没有办法访问App.iOS.Assets上设置的资产,或者我必须将它们移动到共享项目中,在那里我有App.iOS及其扩展都在使用的模型和其他东西


我注意到SoupChef示例中的绑定(OrderIntent所在的项目)与容器应用程序(“SoupChef”)具有相同的名称空间,因此我在项目中使用Xamarin.Forms分配了相同的名称空间,但仍然没有任何内容。

可以从本地文件、嵌入式资源、下载或从流加载图像。选中。这些图标已存在于资源中,并且大小不同。因此,从那里访问它们将是理想的,因此我不需要手动选择大小。这在SoupChef示例中效果很好,但由于某些原因,我无法在Xamarin上使用它。Forms:(创建一个具有不同名称的新图像集。或者可以在表单中重新缩放图像。
CGSize DisplayOrderConfirmation(Order order, OrderSoupIntent intent, OrderSoupIntentResponse response){
/* unrelated code */

Class GetClassForType (Type type)
{
    IntPtr myClassHandle = Class.GetHandle (typeToLookup);
    if (myClassHandle != IntPtr.Zero)
        return new Class (myClassHandle);
    else
        return null;
}

//this returns the bundle identifier of the SoupChef app 
//(not the SoupChefIntentUI) on the SoupChef example
//on Xamarin.Forms (my project) it returns the IntentsUI identifier
var containerBundle = NSBundle.FromClass(GetClassForType(typeof(SoupChef.OrderIntent)));

//the icon is returned
var icon = UIImage.FromBundle("AppIcon", containerBundle, configuration: null);

/* unrelated code */
}