Find path of local image of iOS project in Xamarin - ios

I have an Image view like this:
<Image Source="{StaticResource AppIcon}" WidthRequest="80" HeightRequest="180" IsEnabled="True" ></Image>
Then i want to declare two different paths for either Android and iOS environment as:
<ResourceDictionary>
<OnPlatform x:TypeArguments="ImageSource" x:Key="AppIcon">
<On Platform="Android" Value="/Resources/drawable/splash_logo.png" />
<On Platform="iOS" Value="????" />
</OnPlatform>
</ResourceDictionary>
The problem is that i don't know how load my image from assets catalog in iOS project (android goes ok).
Can anyone help me?

if you are using native resources for Android and Asset Catalog for iOS then use only the name of file as source.
For example:
Files path in native projects:
Android - /resource/drawable-{size}/security.png
iOS - /Assets.xcassets/security.imageset/{name/size}.{png/pdf/json}
Using XAML:
<Image Source="security" />
Using C#:
Image.Source = "security";
(XAML) If the name of file is different for Android and iOS then use the OnPlatform + On tags but value will be still only the name without extension.
<On Platform="Android" Value="security" />
<On Platform="iOS" Value="devices" />
For C# you can use
if (Device.Platform == Device.Android)
Image.Source = "security";
else
Image.Source = "devices";

Related

How to load external xml file in cordova app

I built an app for ios and android 2 years ago where I load and display data from an external xml file.
I am trying to make an updated app, and the data is not showing. Has anything changed with how this is handled in the last couple years? I have tried adding the Network Status plugin as it seems like the issue might be connecting to the data.
I have tried adding access origin="*" to all config.xml files as that was usually my problem before.
This is the code I am using:
else {/* code for IE6, IE5 */ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.open("GET","http://www.example.com/example.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("order");
for (i=0;i<x.length;i++)
{
document.write("<div class=\"bar\"><center><a href=\"");
document.write(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
document.write("\" data-ajax=\"false\" ><img src=\"images/icon-");
document.write(x[i].getElementsByTagName("item")[0].childNodes[0].nodeValue);
document.write(".png\"></a></center></div><br><br>");
}
Yes things have changed a bit due to WKWebView and security
For iOS, use cordova-plugin-ios-xhr and set your preferences to
<preference name="allowFileAccessFromFileURLs" value="true" />
<preference name="allowUniversalAccessFromFileURLs" value="true" />
You can also add these preferences to load external urls
<preference name="AllowUntrustedCerts" value="true" />
<preference name="InterceptRemoteRequests" value="all" />
For Android, set your preferences to
<preference name="AndroidInsecureFileModeEnabled" value="true" />

Xamarin forms iOS apply same font but different style

I have a xamarin forms app. I want to make use of Roboto Font Family, from Google Fonts. Actually, Roboto Light and Roboto Regular. What's the name for Roboto Light and Roboto Regular for iOS?
<OnPlatform x:Key="RobotoLightFontFamily" x:TypeArguments="x:String">
<On Platform="UWP" Value="/Assets/Fonts/Roboto-Light.ttf#Roboto" />
<On Platform="iOS" Value="Roboto Light" />
<On Platform="Android" Value="Roboto-Light.ttf#Roboto" />
</OnPlatform>
<OnPlatform x:Key="RobotoRegularFontFamily" x:TypeArguments="x:String">
<On Platform="UWP" Value="/Assets/Fonts/Roboto-Regular.ttf#Roboto" />
<On Platform="iOS" Value="Roboto" />
<On Platform="Android" Value="Roboto-Regular.ttf#Roboto" />
</OnPlatform>
It does not work like this... It only applies one font instead of both when using each font family foreach component
After some tries, naming it Roboto-Light works.

Visual Studio (Xamarin): DependencyService + Nuget + iOS = Fail

We are writing a Visual Studio (Xamarin) cross-platform application that will share quite a bit of functionality with the next application we write, so we wanted to put that shared functionality into a "library" so we could test it, share it easily, etc.
The only way we found to write a cross-platform library, is to create it using the standard Xamarin DependencyService paradigm, turn it into a NuGet package, and then load that package into our main app. For better or worse, we did this before Microsoft provided a template for generating NuGet libraries like this, so we had to roll it ourselves.
This works fine for Android, but now I'd like to get the same code working for iOS and it's simply not working. No errors, no warnings, but when I run the app and call
Client = DependencyService.Get<IClient>();
It simply returns null. If I look at the Output/Debug window, it is loading the 'Company.Client.Abstractions.dll' (the root DLL containing the definition of IClient) but not the iOS-specific 'Company.Client.dll' (which contains the iOS-specific implementation of IClient).
Here's my nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>Client</id>
<version>0.0.35</version>
<authors>Me</authors>
<owners>Company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Stuff</description>
<releaseNotes>Initial release</releaseNotes>
<copyright>Copyright 2017 Company</copyright>
<dependencies>
<group targetFramework="MonoAndroid">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="Xamarin.iOS10">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
<group targetFramework="uap">
<dependency id="Xamarin.Forms" version="2.3.4.247" />
</group>
</dependencies>
</metadata>
<files>
<!-- Cross-platform reference assemblies -->
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.dll" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.dll" />
<file src="Company.Client.Abstractions\bin\Debug\Company.Client.Abstractions.pdb" target="lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Company.Client.Abstractions.pdb" />
<!-- iOS reference assemblies -->
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.dll" target="lib\Xamarin.iOS10\Company.Client.dll" />
<file src="Company.Client.iOS\bin\iPhone\Debug\Company.Client.pdb" target="lib\Xamarin.iOS10\Company.Client.pdb" />
<!-- Android reference assemblies -->
<file src="Company.Client.Android\bin\Debug\Company.Client.dll" target="lib\MonoAndroid10\Company.Client.dll" />
<file src="Company.Client.Android\bin\Debug\Company.Client.pdb" target="lib\MonoAndroid10\Company.Client.pdb" />
<!-- UWP reference assemblies -->
<file src="Company.Client.UWP\bin\Debug\Company.Client.dll" target="lib\UAP10\Company.Client.dll" />
<file src="Nuvectra.Client.UWP\bin\Debug\Company.Client.pdb" target="lib\UAP10\Company.Client.pdb" />
</files>
</package>
I'm thinking there are two classes of possible problems:
I'm generating the DLL wrong
I'm generating the application wrong
Looking at the generated DLLs, the Android DLL is 28k long, the iOS DLL is 23k, so it doesn't look like the iOS DLL is empty. Is there a tool that would let me inspect the iOS DLL and make sure it has the necessary entry point(s)?
The Project that generates the iOS DLL has these settings:
Target framework: Xamarin.iOS
Output type: Class Library
Condition compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
Platform: Active (Any CPU)
The application that is using the DLL has these settings for the iOS Project:
SDK Version: Default
Linker Behavior: Don't Link
Platform: Active (iPhone)
Supported Architectures: ARMv7 + ARM64
Target framework: Xamarin.IOS
Output type: Console Application
Conditional compilation symbols: __ UNIFIED__;__ MOBILE__;__ IOS__
The interface definition in my 'Abstractions' project looks like this:
namespace Company.Client
{
public abstract class IClient
{
void abstract function();
}
}
and the implementation in my iOS project looks like this:
using Company.Client.iOS;
[assembly: Xamarin.Forms.Dependency (typeof (IosClient))]
namespace Company.Client.iOS
{
public class IosClient : IClient
{
void override function();
}
}
We tried many different ways to create a NuGet package with platform-specific code loaded using DependencyService and every single way had the same problem - worked fine under Android, failed under iOS.
The solution is to create a class in the iOS library that is not loaded using DependencyService, and then in the iOS application, create an instance of that class. That's enough to convince the iOS application that it actually needs to load the iOS library DLL, and then the rest of the DependencyService magic works correctly.

Cordova Tools for VS 2005: iOS app does not display splashscreen and icons

Using VS 2013 Cordova Tools (the current version), my iOS app does not display the given splashscreen and icons unless I set <icon> and <splashscreen> elements in config.xml. However, when config.xml is edited using the visual editor, it simply deletes all <icon> and <splashscreen> elements. Am I missing something?
Obs: icons and splash screen works for android apps out of the box, it just does not work for iOS.
Unfortunately this is a known issue when using the latest version of vs-mda-remote with VS 2013.
You should be able to add this XML to config.xml via Right-Click > View Code to resolve the issue.
<platformname="ios">
<iconsrc="res/icons/ios/icon-60-3x.png"width="180"height="180" />
<iconsrc="res/icons/ios/icon-60.png"width="60"height="60" />
<iconsrc="res/icons/ios/icon-60-2x.png"width="120"height="120" />
<iconsrc="res/icons/ios/icon-76.png"width="76"height="76" />
<iconsrc="res/icons/ios/icon-76-2x.png"width="152"height="152" />
<iconsrc="res/icons/ios/icon-40.png"width="40"height="40" />
<iconsrc="res/icons/ios/icon-40-2x.png"width="80"height="80" />
<iconsrc="res/icons/ios/icon-57.png"width="57"height="57" />
<iconsrc="res/icons/ios/icon-57-2x.png"width="114"height="114" />
<iconsrc="res/icons/ios/icon-72.png"width="72"height="72" />
<iconsrc="res/icons/ios/icon-72-2x.png"width="144"height="144" />
<iconsrc="res/icons/ios/icon-small.png"width="29"height="29" />
<iconsrc="res/icons/ios/icon-small-2x.png"width="58"height="58" />
<iconsrc="res/icons/ios/icon-50.png"width="50"height="50" />
<iconsrc="res/icons/ios/icon-50-2x.png"width="100"height="100" />
</platform>
<platformname="ios">
<splashsrc="res/screens/ios/screen-iphone-portrait.png"width="320"height="480" />
<splashsrc="res/screens/ios/screen-iphone-portrait-2x.png"width="640"height="960" />
<splashsrc="res/screens/ios/screen-ipad-portrait.png"width="768"height="1024" />
<splashsrc="res/screens/ios/screen-ipad-portrait-2x.png"width="1536"height="2048" />
<splashsrc="res/screens/ios/screen-ipad-landscape.png"width="1024"height="768" />
<splashsrc="res/screens/ios/screen-ipad-landscape-2x.png"width="2048"height="1536" />
<splashsrc="res/screens/ios/screen-iphone-568h-2x.png"width="640"height="1136" />
<splashsrc="res/screens/ios/screen-iphone-portrait-667h.png"width="750"height="1334" />
<splashsrc="res/screens/ios/screen-iphone-portrait-736h.png"width="1242"height="2208" />
<splashsrc="res/screens/ios/screen-iphone-landscape-736h.png"width="2208"height="1242" />
</platform>
More known issues: https://www.visualstudio.com/explore/cordova-known-issues-vs
I had similar problem. I simply didn't use graphical config editor and use only text one.
However, the Visual Studio 2015 RC fixes this problem and there is an implicit configuration for every icon and splash screen.

Banner not shown

I started to use advertising control, but I'm going crazy trying to let it work.
I copied PivotPage.xaml from Microsoft Ad Control Sample and made it the starting page in my app, but ad control is not shown (I'm not able to see banner); if I try to run Microsoft app, banner is shown.
So I registered my app on pubCenter and I got an appId and a unitId and tried to use them in my app, but the result is the same: no banner!!
If I try to use my ids in Microsoft app, test banner is shown.
Why using Microsoft example I'm able to see banner and using same page in my app I can't?
Why using my ids, Microsoft app does not show correct banner?
Here is XAML
<!--Pivot Control-->
<controls:Pivot Grid.Row="0" Title="Ad Control Sample">
<!--Pivot item one-->
<controls:PivotItem Header="piv 1">
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="piv 2">
</controls:PivotItem>
<!--Pivot item three-->
<controls:PivotItem Header="piv 3">
</controls:PivotItem>
</controls:Pivot>
<StackPanel Grid.Row="1" VerticalAlignment="Bottom" >
<TextBlock Text="This is the same ad."
TextWrapping="Wrap"
HorizontalAlignment="Stretch"
TextAlignment="Center" />
<my:AdControl Name="adControl1"
ApplicationId="test_client"
AdUnitId="Image480_80"
HorizontalAlignment="Center"
Width="480" Height="80" />
</StackPanel>
I finally managed to solve my problem and I want to share solution.
I add an event handler for ErrorOccurred on ad control and reading Microsoft.Advertising.AdErrorEventArgs e I realized that my manifest (WMAppManifest.xml) was missing
<Capability Name="ID_CAP_IDENTITY_USER" />
<Capability Name="ID_CAP_MEDIALIB" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />

Resources