After solving this problem I ran into another.
I changed the NuGet-package and implemented everything as described here.
I also added the initialization code in the AppDelegate.cs. But if I push the button to login I get the following error message: Uncaught Exception: Target of Invoke is null (NullReferenceException).
What I've done so far:
Create OAuth2Authenticator with appropriate values
Add Event handler authenticator.Completed += OnAuthCompleted;`
Initialized platform specific login UI with global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init(); and global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, bundle);
Triggered the login with:
var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(authenticator);`
I'm using the Xamarin Live Player to deploy this on my iPhone.
Some ideas how to fix this?
UPDATE:
I was able to test the app with a Android emulator and there is everything working. So my assumption is that it's because of the Xamarin Live Player.
Related
I am getting this error message while calling await OktaContext.Current.SignInAsync(); this method of plugin okta.xamarin.
Its working fine with normal mvvm but giving following issue with prism.
Attempt to present <SFSafariViewController: 0x7fe6e396f600> on <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x7fe6e1926e60> (from <Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x7fe6e1926e60>) which is already presenting <Xamarin_Forms_Platform_iOS_ModalWrapper: 0x7fe6e4920ad0>
I have a finished application which I would like to make available to run on the iOS and Android platforms. I have tested the application as much as possible and it works without problem. But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}
I'm currently on developing some little application for iOS and Android. Therefore I need an OAuth2 authentication.
How I proceeded (from here)
Create a new Xamarin.Forms project from the templates with the default Item and About page
Add Dependency for Xamarin.Auth
Use the button on the about page to trigger a function with the following:
var authenticator = new OAuth2Authenticator(
"CLIENTID"
,
"SCOPE",
new
Uri("AUTH_URL"),
new Uri("REDIRECT_URL)
null,
true);
Add the iOS initializer in the AppDelegate.cs global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init();
Add the URL Types in Info.plist
I'm using the Xamarin Live Player to deploy this on my iPhone 7. When I'm triggering the button, I get the following error message:
Uncaught Exception: Bad convert with overflow instruction 'IL_0001: conv.ovf.i.un' (NInterpretExcetion)
Some ideas how to fix this?
I am using Visual Studio App Center for my Xamarin Forms Android Application for capturing the Analytics(Events and Crashes)
I am configuring crashes and analytics in OnStart of my App.Xaml.cs
AppCenter.Start($"android={Settings.Current.AppCenterAnalyticsAndroid};" +
typeof(Analytics), typeof(Crashes));
And for invoking the Events I am calling the below Method.
public void TrackEvent(string name, Dictionary<string, string> properties = null)
{
Analytics.SetEnabledAsync(true).ConfigureAwait(false);
Analytics.TrackEvent(name, properties);
}
Crashes are logging correctly in App Center But the events are not.
Also I can see the corresponding entries in Log Flow
Your app secret string is invalid because it contains + typeof(Analytics), it should be , typeof(Analytics).
Since you used the android key/value delimiter we could extract the appSecret and make it work with Crashes, but typeof(Analytics) ended up in the wrong appSecret parameter string.
You shouldn't need to add Analytics.SetEnabledAsync(true).ConfigureAwait(false);
Simply Call Analytics.TrackEvent(name, properties); (it doesn't need to be in a task anyways. I track my events in the Construtor of pages, for example.
Also, when you run the application, you get a debug Message confirming that AppCenter has been configured correctly, check if that is the case.
And, it may take a while, for them to appear in the Events.
I am working on facebook authentication in a Xamarin forms app and want to use "native" login on each device.
The Facebook SDK (by Xamarin) is not designed for forms since it requires passing in an Android activity that implements some specific interfaces.
However; I was able to get the UI to display using a custom page renderer and then in that renderer calling StartActitivty with an activity that uses the exact implementation described in the Facebook SDK getting started. https://components.xamarin.com/view/facebookandroid
So far everything works perfect. The android app starts, xamarin forms kicks in, the custom page renderer is loaded the login android activity starts and the user logs in with facebook and we get to the console.writeline below.
So, how do I dismiss this intent or otherwise get back to xamarin forms?
Do I:
Dismiss this intent? - if so then what?
Inject something to "reset" the main page?
Other?
public void OnCompleted (Xamarin.Facebook.Model.IGraphUser user, Response response)
{
//TODO: show user details with welcome and button that takes them to main app.
//TODO: switch back to xam forms from here on out.
//TODO: figure out how to change the `main` activity to xam forms.
// 'Me' request callback
if (user != null) {
//How do I get back to Xamarin forms from here?
Console.WriteLine ("GOT USER: " + user.Name);
} else {
Console.WriteLine ("Failed to get 'me'!");
}
}
You should call Finish();
Anyway, if you want to see exactly how I did it, you can check it here:
https://github.com/IdoTene/XamarinFormsNativeFacebook