-1

Currently I am using the Xamarin forms for creating the Android and iOS. Now I am using the OAuth2.0 for login functionality. So I have created one view controller in Xamarin iOS project. In the AppDelegate class, I am calling my controller view from the FinishedLaunching method.

Like:

var mainController = new ViewController(); // Your view controller here
 mainController.ViewDidLoad();

in the ViewDidLoad write the logic of the OAuth2.0 and used the this.PresentViewController(authGui, true, null). But in my project it is not redirecting to page and give the below warning

Warning: Attempt to present <UINavigationController: 0x7fde4a9d6800> on
<ViewController: 0x7fde4a53f9d0> whose view is not in the window hierarchy!
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Mar 27 '18 at 20:25
  • This post needed significant reformatting, and was largely unreadable in its first iteration. It's a bit better now I have edited it. Please make an effort to learn the formatting tools here, and supply your questions in a readable form the first time around, to reduce volunteer editor workload. – halfer Mar 27 '18 at 20:26
  • I will take care of it next time. Thanks. – AbhishekK21 Mar 28 '18 at 07:27

1 Answers1

0

There's no need to trigger ViewDidLoad() event manually. We assume you use the blank app template. You should set the Window's RootViewController to show it, then the ViewDidLoad() event will fire. Please read this documentation about iOS UIViewController for more details, also refer to this post about UIViewController's lifecycle.

After you have brought this mainController into Window, you can use this.PresentViewController(authGui, true, null) to present the OAuth view on the screen.

Authenticating Users with an Identity Provider tells you how to implement OAuth on each platform, you should read it more carefully. Besides on iOS if you want to redirect back to your app, set a custom URL scheme in Info.plist. When it comes back, the event OpenUrl() will be called, override it in the AppDelegate.cs.

Ax1le
  • 6,563
  • 2
  • 14
  • 61