I am using Visual Studio For Mac. My Xamarin Forms project is quite large and contains many content pages. Some of them will be only used in android project and some of them only used in iOS project. There is no problem when I compile the project into android. However, when I want to compile the project into iOS, it seems like did not accept anything related to android. Please refer to the screenshot. There is no way I can include the android specialised reference and compile into iOS project. So, any idea to deal with this? Maybe there is a way to force build the iOS project no matter what? The error from the screenshot is from the page that will be only used in android. So what I can do for now is delete the page when I want to compile as iOS and recreate the page when I want to used it for android. But there are plenty of them, it is too heavy for me to do this every time. Please help.
You can't call platform specific APIs at the .NET standard libraries that are used to host Xamarin.Forms code by default.
Basically you have those options:
1) using shared project instead of library and using conditional compiling (easier but it is now not available as the option when creating the project)
2) using dependency injection.
Related
So yesterday this line:
ATTrackingManager.RequestTrackingAuthorization((status) => {
if (status == ATTrackingManagerAuthorizationStatus.Authorized)
{
}
was working code (in my cross-platform Xamarin.Forms PCL).
Today xamarin.ios received an update.
In the PCL project, the tracking manager is not found anymore. Intellisense doesnt know what it is anymore and I cannot debug the app.
It is recognized in the xamarin.ios project, but I need to access it from my PCL.
Anyone having the same issue and / or has already found a solution?
How can I rollback to xamarin.ios before the one I received today?
Don't need to rollback. As a test, I updated
Visual Studio (which also updated Xamarin.iOS).
XCode to 14.5.1.
Then I added a line of code to an existing Xamarin Forms solution, that referenced AppTrackingTransparency.ATTrackingManager. This was recognized as valid code. I Also tried just ATTrackingManager, and Intellisense correctly told me I needed using AppTrackingTransparency.
So its there now.
That namespace+classname is specific to iOS, so must be referenced from the iOS-specific project. (If it previously was referenceable in the PCL, that was probably a bug that has since been corrected; such code would break on any other platform.)
First step:
In your iOS project, write code that references that class.
Second step:
You need to know how to use your custom iOS code from the cross-platform Xamarin Forms PCL.
I won't repeat that here - there are multiple Q&As on that topic.
google "stackoverflow xamarin forms call platform specific code".
I'm using a new project that's using sql-lite-pcl and it doesn't appear to be loading the required dependency packages (recursively). I know this because "it just doesn't work (tm)"
I've been able to get the project to work by adding the following on the Xamarin Forms project and the iOS project
SQLite-net-pcl
SQLitePCLRaw.bundle_green
SQLitePCLRaw.core
SQLitePCLRaw.lib.e_sqlite3.ios
SQLitePCLRaw.provider.dynamic_cdecl
SQLitePCLRaw.provider.internal.ios_unified. (iOS only)
SQLitePCLRaw.provider.ios_inified (iOS only)
For most of the items above I needed to install a 1x version, whereas the 2.0 version of SQLite reported a variety of errors from the SQLite-net-pcl library. (there is an open GIT issue on the project page for 2.0 support)
Question
How do I verify (in runtime?) that I'm using the native iOS provider?
Does it matter if I switch between the iOS provider and the code- based one? In either data binary reading and writing, locks, app suspension/closing handles, performance or any other reason?
What are the correct libraries to load if simply adding sql-lite-pcl into a Visual Studio for Mac doesn't recursively load all dependencies, and the correct version of them?
There is a very good tutorial how to use SQLite for Xamarin Forms. You can find it here.
It's working fine both for Android and iOS version
How do you setup google firebase dynamic links, deep linking, in a xamarin forms app?
This is how I setup Firebase Dynamic Links in Android project of my Xamarin Forms App, so most of this will apply directly to android. I will work on finishing and documenting the iOS implementation in the future.
Disclaimer: I'm not an expert, any or all of this could be wrong. It's just what worked for me and my basic understanding. Please let me know if there are any errors and let's improve our collective intelligence of the Xamarin Community
If you don't already know what Dynamic Links are, watch the 2 min video, it's a great overview. https://firebase.google.com/docs/dynamic-links/
The Setup
Setup is broken up into 2 parts.
Part 1 - Configure the Dynamic Links in the Firebase Console (Easy)
Part 2 - Configure your app to be able to receive and process the Deep Links (Not as Easy)
Part 1 - Configure the Dynamic Links in the Firebase Console (Easy)
1- Setup a free firebase account at https://firebase.google.com/
2- Create a project.
3- Create a new dynamic link, the tab is at the bottom of the 'Grow' section.
It will generate a static domain name for you based off of your project name. Ex. 'https://myproject.page.link'
Short Link url is what users will click on to navigate to your appstore or launch your app.
Deep Link url is what actually gets sent into your app for you to work with. Ex 'https://myproject.com/MainPage'
iOS behavior. Currently set mine to open the link in a url browser, as my app is not connected to it yet.
Android behavior Very Important but not as hard as my explanation makes it look.
Here is where you register your app with firebase. The package name should be easy, use the same one as defined in your
apps Android properties. Ex 'com.mycompany.appname'
Adding the signing certs SHA-1 and SHA-256 are required for Dynamic Links, which is what we are doing here.
Microsoft has a great guide on this, better than I can explain. here
Download the google-services.json file - You will need it later. Also, you will need the one that has incorporated the SHA cert details in it.
Ignore the instructions for adding the firebase SDK, we will add these to our project later using Nuget packages.
When this is all done your app should be selectable in a dropdown for the android behavior.
Finally, add any extra tags to your dynamic link url if you want, its optional.
And that's it! Now you should have a working short link. When used on an android device it should already be able to determine if the app is already installed or not, and then either direct the user to the play store or open the app. However, it won't do anything with that deep link url that you set. That brings us to the next part.
Part 2 - Configure your app to be able to receive and process the Deep Links (Not as Easy)
1- Versions, might be important.
2- Nuget Packages - Hopefully this goes smoother for you than it did for me.
3- The Code
3a- Intent Filters
3b- Handling the Deep Link
1- Versions.
I was having a lot of issues trying to get dynamic/deep linking to work. So I went back and updated everything to the newest versions available at the time.
Visual Studio Professional 2017 - 15.7.5
.NET Framework 4.7.03056
Xamarin 4.10.10.2
Xamarin.Android SDK 8.3.3.2
Android SDK Manager - Got the latest. Android 8.1 API 27 and Android 8.0 API 26 (Targeting 8.1 might be required)
Android Properties -
-Application - Compile using Android Version(Target Framework): Android 8.1 Oreo
-Android Manifest: Target Android Version: Use Compile SDK Version(haven't tried targetting 8.1 directly, might work). My min target is still Android 4.4 API 19 Kit Kat
2- Nuget Packages. These are just for the Android project. MyApp.Android
You shouldn't have to add anything into the .NET Standard Project, just make sure the Xamarin.Forms Versions match
Below is what I did
Update:
Xamarin.Forms - updated to 3.0.0.482510
Install:
This is where it immediately got annoying for me. Issues here are what lead me to go back and update my Android API Levels to the most recent, 8.1
Xamarin.Firebase.Dynamic.Links by Xamarin Inc v60.1142.1 is what you want to install.
The other dependencies should automatically install. In my case, they did not.
Dependency MonoAndroid,Version=v8.0 is important here. That should be the SDK API version that your app is set to compile against.
However, the other dependencies like Xamarin.GooglePlayServices.Basement (= 60.1142.1) have nested dependencies of their own that require MonoAndroid,Version=v8.1
So if you run into issues installing the Dynamic Links Package, thats where I would recommend looking first.
For my purposes, the nested dependencies were not automatically getting installed, so I went down through each of them and their lists and did them all manually. Even the ones that said not to do manually. It's only 20 or so, but my guess would be if I had my project SDK's set to 8.1 before all of this that it would have gone smoothly.
The CODE
Intent Filters
These are defined in your AndroidManifest.xml file
What do they do? They listen for instructions while your app starts.
When an app start matches a pre-defined filter(short link), they it stores your intended action or data on the Intent Class. That is where we pull the deep link from.
For us, this is what let's the android app receive and begin to process the deep link url that you set all the way back in Part 1.
The firebase dynamic link docs have a good breakdown and example of what to do. here
The android developer docs have a good example and breakdown of this also. here
NOTE Focus on whats between the activity tags. I've just included the other tags to show general structure, in case you haven't edited these before.
That is about the minimum of what you need.
The highlighted line should match the Short Dynamic Link you setup in the established in the Firebase Console.
I'd recommend using a Wildcard like I did in the path prefix.
That way you can make new Dynamic Links and your app can handle them without having to release new versions.
Handling the Deep Link
At this point if your app is launched by the short link, you should be able to catch the deep link during the android startup process and handle it how you want.
All I will cover here is a basic example of how to get the Deep Link as a string.
I pass mine to the main app project (.NET Standard Library) using a simple dependency service.
You can use it however you want though, there's actions it can take in either the App or the App.Android project.
The important thing is getting the deep link.
The firebase docs have good examples, but written in java or whatever language native android uses. here
I'll be showing mostly the same, just in C# examples
Get The Intent.
What is the intent you want to get? The deep link you are sending into your app Ex. "https://mycoolapp.com/mainpage"
You want to get it in the MainActivity. Below is an extremely simplified example, but it's just about that easy. Now you should be able to do what you want with that link inside of your app.
TIPS
Be careful if you have something that interrupts your startup procedures.
My Application uses a splash screen. Part of that is a line of code that creates a new Intent, overwriting the one sent in from the dynamic link
So I have my DeepLinkHandler fire off before that operation, and store the deep link in a static string.
Once it's in a static string I can use a dependency service from the Main App(.NET Standard Library) to call the GetDynamicLinkString method and return the deep link as a string.
How to Test Using an Emulator and Debugger
I have a simple settings page on my app. I added a field that would print the deep link, if it has one.
Fire off the emulator like normal using the debugger. The deep link field should be empty.
With the emulator still running, minimize the app.
Open a browser and enter in the short link url.
This should re-launch your app, but this time the deep link field has the url that you set on the firebase console.
Hope this is able to save someone some headaches.
-Tim
I want to rewrite my old .net app based on FirebAse with the new C++ SDK, I have managed to link and compile the libraries in my VS2015 environment, but now have no idea about how to use them.
The firebase quick start here:
https://github.com/firebase/quickstart-cpp/tree/master/auth/testapp/src/desktop
doesn't really show anything.
Am I looking in the wrong place?
Cheers.
Firebase C++ only provides stub libraries as a convenience for desktop at the moment so while you'll be able to link the libraries they won't actually do anything. We have a desktop implementation of our light platform abstraction layer for internal testing only - notice we don't ship desktop MSVC or Xcode projects.
See the readme.md in the Firebase SDK zip file for more information.
I am new xamarin.forms framework, When I started to work for cross platform application for making new solution (new solution->mobile apps), I got following three options for moving further:
Blank App(Xamarin.Forms Portable)
Blank App(Xamarin.Forms Shared)
Class Library(Xamarin.Forms Portable)
After investigating a lot, among those i did not create any difference. Can anyone tell me the difference with example.
Xamarin has the answer to your question here, but I'll give you a short rundown here as well.
Class Library(Xamarin.Forms Portable)
Is an Portable Class Library you can put classes in, which would then be usable by either an Android, iOS or WP app.
Blank App(Xamarin.Forms Portable)
Creates a set of apps for Android, iOS and possibly WP using a Portable Class Library for the common parts
Blank App(Xamarin.Forms Shared)
Creates a set of apps for Android, iOS and possibly WP using a Shared Library for the common parts
The difference between PCL and Shared is that a PCL library is compiled once, and then referenced as a library by each app. A Shared library is compiled directly into each app (and is thus compiled three times as opposed to one for the PCL)