IF condition for Xamarin.iOS and Xamarin.Android in Xamarin project - xamarin

I am new to the Xamarin and trying to create Liveswitch project (https://help.frozenmountain.com/docs/liveswitch/release-notes)
Project this : Liveswitch demo project have Xamrine project which had below structure:
Shared project (it has Chat.shproj)
Android project
iOS project
I wanted to create Xamrine Project
Xamarin Project (this has Chat.csproj)
Android Project
iOS project
When i try to use. Xamarin Project (this has Chat.csproj) and code app.xaml.cs like below :
#if __ANDROID__
using Android.Content;
#endif
using FM.LiveSwitch;
using System;
using Xamarin.Forms;
namespace Chat
{
public partial class App : Xamarin.Forms.Application
{
#if __IOS__
public App()
{
#else
public App(Intent screenshareIntent)
{
#endif
InitializeComponent();
#if __IOS__
MainPage = new NavigationPage(new SessionSelector());
#else
MainPage = new NavigationPage(new SessionSelector(screenshareIntent));
#endif
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
It shows me error that Intent not found. i.e it is not allowing me to write conditional coding for method definition for Android and iOS in different way.
But in Shared project it is allowing me to write it.
Is there any way i can do that in Xamarin project ?
I am using visual studio for MAC version 8.5
Other problem is if i user Shared project and try to use
LoadApplication(new App(screenCaptureIntent));
MainActivity.cs not able to find files in the sharedproject. How can i connect files of shared project with files in android and iOS project in Xamarine.

Related

Unable to use WifiNetworkSpecifier in Xamarin

I tried to use following code snippet in my XAMARIN project using Visual Studio (Windows 10, Android platform API 29).
WifiNetworkSpecifier.Builder builder = new WifiNetworkSpecifier.Builder();
But looks like "WifiNetworkSpecifier" is not available for Visual Studio.
Error: CS0246 The type or namespace name 'WifiNetworkSpecifier' could not be found (are you missing a using directive or an assembly reference?)
Please share workaround to resolve this issue.
VERSION DETAILS ARE AS FOLLOWS:
Microsoft Visual Studio Community 2019, Version 16.6.2
Xamarin.Android SDK 10.3.1.4 (d16-6/3a10de9).
First, right click Android project => Property => Application and choose the Target Framework to Android 10.0(Q) or higher:
Then in your project, reference the namespace:
using Android.Net.Wifi;
Then you can use WifiNetworkSpecifier in your project:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
WifiNetworkSpecifier.Builder builder = new WifiNetworkSpecifier.Builder();
}
you need to specify the namespace
using Android.Net.Wifi;
is VS, right clicking on the line that has the error should offer you a prompt to automatically suggest potential fixes

How can I add Xamarin Forms to F# Xamarin Android project?

Create an app using the "Blank App (Android) F#" template in Visual Studio 2019
Try to add Xamarin Forms
Xamarin Forms cannot be added?
What happened? How can I add Xamarin Forms into an F# Xamarin Android project?
First of all, you cannot add the xamarin forms nuget packages to you xamarin native project.
The right process is you can create a xamarin forms project, then you can add the xamarin forms package in the xamarin android platform like this screenshot.
I think you should consider Xamarin.Forms Embedding.
It enables a Xamarin.Forms' ContentPage to be incorporated into a Xamarin.IOS or Xamarin.Android app.
I have used it before and it had a significant performance cost to it when loading the content page.
Here's the Android documentation.
public class MainActivity : AppCompatActivity
{
public static string FolderPath { get; private set; }
public static MainActivity Instance;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
Forms.Init(this, bundle);
Instance = this;
SetContentView(Resource.Layout.Main);
...
Android.Support.V4.App.Fragment mainPage = new NotesPage().CreateSupportFragment(this);
SupportFragmentManager
.BeginTransaction()
.Replace(Resource.Id.fragment_frame_layout, mainPage)
.Commit();
...
}
...
}

Xamarin Java Library Binding issues

I want to use agency tango materialintroscreen library in my Xamarin.Android project.
I have created a Xamarin Android Binding Project, copy the ARR file in the Jars Folder and set Build Action to LibraryProjectZip.
Then I reference the project in my main Xamarin.Android project.
Normally I can access to agency.tango.materialintroscreen but have the error the namespace doesn't exist.
I try to use jetBrains dotpeek I saw dll was create well with all class.
I have the same error with 3 library
Visual Studio Error list
Object Browser

Errors while using Sqlite-net on Xamarin studio

I am using sqlite-net in Xamarin Studio for Xamarin.forms application. In that I have put the sqlite-net library version 1.0.8. I have created the interface which I would be implementing in the platforms. But when I try to compile the PCL project I am getting a lot of errors which are present in the SQLite.cs file which was added when I added the PCL for sqlite-net.
I initially thought that the file is not important but it started giving more errors in the application. How to resolve this issue?
I am using a video tutorial for which used Visual studio for making the sample.
I am attaching the pic for the same. I would like to mention that the problem is not in my file the compile time errors are in the library.
EDIT: The PCL version of the package is 1.0.8
I had added the file in the application with content
using System;
using SQLite;
namespace SQLiteExample
{
public interface ISQLite
{
SQLite.SQLiteConnection GetConnection();
}
}
You should use SQLite-Net-PCL instead of SQLite-Net.

Add ios project to xamarin forms solution with droid project

I've got a xamarin forms solution with a pcl and a .Droid project. Now I also want to add ios to the solution. How do I do this. From the add dialog I can select add new project, but it seems to add a lot more....So the solution was first created without the ios checkmark....
btw. I'm using xamarin studio
Best regards
Add new Empty iOS project.
Add Xamarin.Forms Nuget package.
Substitute your AppDelegate class with this one:
[Register ("AppDelegate")]
public class AppDelegate : FormsApplicationDelegate
{
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
Xamarin.Forms.Forms.Init();
LoadApplication (new App ());
return base.FinishedLaunching(application, launchOptions);
}
}
There is not a Xamarin.Forms project template that will do this out of the box. The Xamarin.Forms project templates are designed to be stand alone and ready to run after being created so they will always create a PCL project or a shared assets project.
Artur's answer, of creating a new empty iOS project, adding Xamarin.Forms NuGet package, then modifying the AppDelegate, is a good approach. Although it is missing:
Add reference from the iOS project to the PCL project.
If you compare that with the iOS project created using the empty project with the one created using the Xamarin.Forms project template they are slightly different. So an alternative to creating a new empty iOS project would be:
Create a new Xamarin.Forms solution with the iOS check box selected.
Copy the iOS project into folder inside your existing solution.
Add the iOS project to your existing solution.
Add a reference from the iOS project to your PCL project.
You could try adding a new Xamarin.Forms project to the existing solution using the New Project dialog without creating it separately. I would be careful doing this it may try to overwriting existing project files. If you have already done this then you should be able to remove the new PCL project it added and also the new UITests project it added. Then add a reference from the iOS project to your PCL project.

Resources