Xamarin.Forms: How to request ACCESS_BACKGROUND_LOCATION? - xamarin.forms

Using XF 5.0.0 and Essentials 1.7.0. Targeting Android 11.0, API 30.
I'm already requesting ACCESS_FINE_LOCATION because I use Plugin.BLE.
I've added Microsoft.AppCenter.Analytics to my XF app, and that seems to require the ACCESS_BACKGROUND_LOCATION permission (the app crashes & an exception tells me so).
There's no item for ACCESS_BACKGROUND_LOCATION in the Project Properties / Required Permission list, so I manually added it to AndroidManifest.xml. It compiles, but still crashes.
I've also read that you can't request both ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION at the same time, that _FINE must be granted first, then you must request _BACKGROUND. Is that true?
Additionally, I'm requesting LocationAlways programatically:
var status = await Permissions.RequestAsync<Permissions.LocationAlways>();
because it seems you can't do that one in the manifest.
And I'd be fine with requesting Background Location programatically, but Xamarin.Essentials.Permissions doesn't offer that.
So I'm stumped!
Does anyone know how to request both ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION in a Xamarin.Forms app?
Thanks!

Related

Invalid Dynamic Link on accessing https://app.page.link (no query params)

Here is my Firebase Dynamic Links page:
On running this command: npx uri-scheme open "https://app.page.link" --android - notice there is no query params in the link, a web page is opened on Android as expected, but with the following content:
It is working find when I add /c8Ci or /bbb at the end, but it throws me the error above when the link is clear (without any query params)
To be short:
Android:
https://app.page.link/bbb - success (app launched)
https://app.page.link/c8Ci - success (app launched)
https://app.page.link - fail
iOS
https://app.page.link/bbb - success (app launched)
https://app.page.link/c8Ci - success (app launched)
https://app.page.link - success (app launched)
Can you please help me to figure out what's wrong with my Dynamic Linking.
Thank you mates in advance!
It is an expected behavior when you try to open the "https://app.page.link" directly, as its purpose is solely for Dynamic Links domain only. Note that Firebase provides a default 'page.link' subdomain for your Dynamic Links for free, this is because you can't use the same domain for both Dynamic Links and regular hosting. The domain is not configured to behave as a regular Hosting domain.
This is why configuring a short link URL allows you to redirect your users to you app. And visiting the domain directly returns an invalid page.
As for iOS, I can only assume it was cached that’s why it worked.
I guess it is best reaching out directly to Firebase support regarding this as there could be any other underlying reasons that could cause this.

xamarin.forms: ios cannot create async on firestore. failing with with "bad gRPC response"

I created an empty xamarin forms project and followed the path to connect to the database. I am able to connect with the right key store file but as soon as I try to create data on the server I am getting a bad grpc response.
It look like ios is calling with http 1.1, but google requiers 2.0.
This is the line that fails:
await docRef.SetAsync(user);
This is the error I am getting:
e {Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.") at Google.Api.Gax.Grpc.ApiCallRetryExtensions+<>c__DisplayClass0_0`2[TRequest,TResponse].<WithRetry>b__0 (TRequest request, Google.Ap…}
I am stuck here for days now, please help.
The same code works fine on android devices, its just iOS problem in xamarin.forms.
EDIT:
I have noticed, that this issue does not exist on the firebase nuget package 3.2.1 and below. Just the higher ones throw this error.

does "app_key" means the same as "app_code" for HERE geocoding credentials on Python?

I am trying to geocode some addresses with python
so I created a freemium account on https://developer.here.com
my code is this
(...)
here = Here(here_config.app_id, here_config.app_code, timeout=5)
here.geocode(string_to_geocode)
I am getting the following error message:
HTTP Error 401: Unauthorized
my doubt comes from the difference between the terms "app_code" on my code sample and "app_key" on my credential screen.
Is there another step I need to do in order to get a "app_code" or is my "app_key" already supposed to be it?
P.S. on that same screen Here provides me an option of getting JAVASCRIPT keys, HERE SDK FOR IOS (PREMIUM EDITION) [this option cleary has a button that says "generate app_key and app_code", however, I am not developing a cellphone app, but a python program.
What am I missing ?
here_credential_screen
App ID and App Code have been replaced. We encourage all users to switch to API Key or OAuth 2.0 (JSON Web Tokens) authentication. Please be aware that as part of adapting to the new authentication method, some endpoints have also changed.
please check the new domains here
You can either use your ApiKey or App_Id/App_Code.
for example like this-
https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey={YOUR_API_KEY}&searchtext=425+W+Randolph+Chicago
https://developer.here.com/documentation/geocoder/dev_guide/topics/quick-start-geocode.html

IdentityModel.OidcClient library doesn't seem to work with UWP

We are using ASP.NET Identity with IdentityServer4. We've added a Client to use with Azure AD. This works great within a web page, that part is working.
Our end goal is a UWP app, so we found the IdentityModel.OidcClient which has a UWP sample. This sample has two browser classes. We configured HTTPS, but the WabBrowser class now refuses to connect to the site at all. If I change the config to hit https://demo.identityserver.io then it works, but all the other config is the same, so I'm not sure what the problem could be. It shows an error message in the pop up browser that it could not connect.
I looked at the SystemBrowser class, but this logs in fine, then the browser window does not close, and even if we close it, the code doesn't move on to get back a result. Looking at the source, this is not surprising, it calls:
Launcher.LaunchUriAsync(new Uri(options.StartUrl));
and that's all. The RedirectUri is not passed in, and mechanism appears to exist to use it. So, the behaviour we see appears to be the extent of what the class can do.
Looking at the console .NET Core sample, it has a SystemBrowser class that works. I updated the UWP sample to use the Fall Creators Update and was able to bring in the ASP.NET Core dlls needed to compile this code. It sets up a class like this:
public LoopbackHttpListener(int port, string path = null)
{
path = path ?? String.Empty;
if (path.StartsWith("/")) path = path.Substring(1);
_url = $"http://127.0.0.1:{port}/{path}";
_host = new WebHostBuilder()
.UseKestrel()
.UseUrls(_url)
.Configure(Configure)
.Build();
_host.Start();
}
and I can confirm this gets called only once, but even if I hard code an unused IP address, I get an error that the IP is in use.
So, at this stage, the sample that exists for UWP works for the demo server but not for ours (I suspect an HTTPS issue, but that's not the error I get), and importing code that works for a Core sample, does not work either. I've spent a couple of days on this and would appreciate a nudge in the right direction.
So, to recap, the WabBrowser seems the best bet but, for my localhost IdentityServer I get this:
and if I try to use a .NET Core library that works elsewhere, it thinks a port is in use. I suspect I need to work out why WabBrowser can't connect to my local site. I have turned off Fiddler. I can browse to my https URL and get a disco document, in the browser, at https://localhost:44305/.well-known/openid-configuration.
There are extra steps necessary to enable localhost in the Web Authentication Broker -
https://msdn.microsoft.com/en-us/library/windows/desktop/jj658959%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
This website gave me the fix. Here is a synopsis:
Remove loopback isolation
For security and reliability reasons, UWP applications are not allowed to send requests to the loopback interface. While Visual Studio automatically creates exemptions for debugged apps, this feature won't be helpful in this case, as the authentication broker always executes in a separate process.
If you see this (cryptic) error message in your Windows event logs, then you're likely facing this issue:
AuthHost encountered a navigation error at URL: [...] with StatusCode: 0x800C0005.
One option to fix it is to use the loopack exemption utility developed by Eric Lawrence. It's natively included in Fiddler 4 but can also be downloaded as a standalone software. To allow the authentication broker to communicate with the loopback interface, exempt the applications starting with microsoft.windows.authhost and save your changes:
If everything was properly configured, you should now see the login/consent page returned by your server.

Invalid token because of wrong audience?

I just made a firebase project, installed the pods and got the googleplist in, configured it in the app delegate, and set it up exactly like I have other projects.
For my pods, I've got exactly what I have in my main other project :
pod 'Firebase/Core’
pod ‘Firebase/Auth’
pod ‘Firebase/Database’
When I run this code :
let ref = FIRDatabase.database().reference()
ref.setValue("hello")
I get an error that pops up like 50 times that says :
MyProjectName[209384092:9028304928034randomnumbers] [FirebaseDatabase] Autentication failed: Invalid_token (audience was project 'a random project from my firebase console' but should have been project 'myProjectName'.
I thought maybe I had done something really goofy at first, so I deleted my project entirely and reinstalled a new google.plist and redid everything, but the only thing that has changed is now I'm just getting a different random project from my firebase project list.
What's goin' on here?
I had the same error as you got, but it only occurred in simulator.
To fix this issue I had to reset my simulators content and settings.
If anyone is experiencing this issue on an actual iPhone device rather than the simulator the root cause of this issue is provided in another SO thread:
Swift/Firebase Database invalid token error
It looks Firebase plan to address it in a future SDK update but to resolve it for now you must sign-out + invalidate your Firebase Database session in your 'old' project first:
NSError *error;
[[FIRAuth auth] signOut:&error];
if (error) {
ELog(#"Firebase Logout failed: %#", error.localizedDescription);
}
Your 'new' project should then now function as expected.
Maybe you are not taking the correct apiKey and authDomain. Go to Firebase, select the project go to Authentication and then Web Setup and see if the apiKey and authDomain are the same keys that you are using in the firebase.initializeApp({});

Resources