Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question ViewController upgrade from SFSafariViewController to ASWebAuthenticationSessionin in Obj C

Discussion in 'iOS and tvOS' started by RendergonPolygons, Jun 15, 2021.

  1. RendergonPolygons

    RendergonPolygons

    Joined:
    Oct 9, 2019
    Posts:
    98
    Hey all,
    I am trying to get to work AppAuth plugin for Unity3D and upgrade this Unity project from SFSafariViewController to ASWebAuthenticationSession.

    The iOS SafariView.mm plugin where I'd need to make this change in the UIViewController to launch the browser needs to be in objc in Unity. I can't code in objc. Can someone please recommend what change I need to make to the this code please.

    Code (CSharp):
    1. #import <SafariServices/SafariServices.h>
    2.  
    3. extern UIViewController * UnityGetGLViewController();
    4.  
    5. extern "C"
    6. {
    7.   void launchUrl(const char * url)
    8.   {
    9.     // Get the instance of ViewController that Unity is displaying now
    10.     UIViewController * uvc = UnityGetGLViewController();
    11.     // Generate an NSURL object based on the C string passed from C#
    12.     NSURL * URL = [NSURL URLWithString: [[NSString alloc] initWithUTF8String:url]];
    13.     // Create an SFSafariViewController object from the generated URL
    14.     SFSafariViewController * sfvc = [[SFSafariViewController alloc] initWithURL:URL];
    15.     //Start the generated SFSafariViewController object
    16.     [uvc presentViewController:sfvc animated:YES completion:nil];
    17. }
    18.  
    19. void dismiss()
    20. {
    21.    UIViewController * uvc = UnityGetGLViewController();
    22.    [uvc dismissViewControllerAnimated:YES completion:nil];
    23. }
    24. }
    Thanks for your help!
     
    mertbsn likes this.
  2. HyungonKim

    HyungonKim

    Joined:
    Mar 11, 2018
    Posts:
    11
    You can use this code to open a browser. You can set up a deep link and handle the redirect in the Unity code.