Moved: Error

Welcome! Forums Unity Plugins In-App Web Browser Moved: Error

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1438
    JezPez
    Participant

    Hi Piotr,
    I also am having this issue on iOS.

    Looking at you excellent example scene : “ExampleJavaScriptCommunicationScene”
    I can see that you need the InAppBrowserBridge to be present in the root of the scene to receive the callback and other browser events.

    I added InAppBrowserBridge prefab to my scene, but now in Xcode I can’t build. I’m getting 2 errors:
    :-1: Undefined symbol: _OBJC_CLASS_$_InAppBrowserViewController
    :-1: Undefined symbol: _OBJC_CLASS_$_InAppBrowserConfig

    With this message:
    Undefined symbols for architecture arm64:
    “_OBJC_CLASS_$_InAppBrowserViewController”, referenced from:
    objc-class-ref in iOSInAppBrowser.o
    “_OBJC_CLASS_$_InAppBrowserConfig”, referenced from:
    objc-class-ref in iOSInAppBrowser.o
    l_OBJC_$_CATEGORY_InAppBrowserConfig_$_DisplayOptionsStruct in iOSInAppBrowser.o
    ld: symbol(s) not found for architecture arm64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Any ideas?
    That sample scene works fine when I build an iOS package (ExampleJavaScriptCommunicationScene) so I can’t figure it out.

    #1441
    PiotrPiotr
    Keymaster

    I moved this reply to new topic as it didnt seem to have anything related to original topic.

    It seems you are missing those files (InAppBrowserViewController.mm) from your output Xcode project.

    #1445
    JezPez
    Participant

    You were correct, I had removed the InAppBrowserViewController.mm Thanks!

    I am having another issue now. My browser session ends in a 302 redirect to the apps custom Url Type, when I would like to close the browser and come back to the application. I know this Url works to open the app because, from a link, I am able to launch the app.

    But when this In App Browser receives the 302 redirect, I see the following error in the logs in Xcode:

    ERROR:Error Domain=WebKitErrorDomain Code=102 “Frame load interrupted” UserInfo={NSErrorFailingURLStringKey=com.jigspace.jigsignupsample://dev-jigspace.auth0.com/ios/com.JigSpace.JigSignupSample/callback?code=QlT1tYAYMyb5aR2&state=itsastate
    InAppBrowserBridge:OnBrowserFinishedLoadingWithError(String)

    What should I do to close the browser upon receiving a redirect like this?

    BTW: I am trying to achieve an OAuth2 interactive flow.

    #1446
    JezPez
    Participant

    I figured it out.

    Seems like the WebView may always throw a Domain=WebKitErrorDomain Code=102 “Frame load interrupted” when it encounters a redirect.

    Anyway you are still able to register for the openUrl in an AppDelegate .mm class of your choosing.

    To help some future Googlers who come here, this is how I was able to do it:

    1. Register a Url in Unity for iOS: PlayerSettings > Other Settings > Supported URL Schemes > Here, add your apps url identifier. EG: com.Company.ProjectName
    2. Make a new Unity Game Object Prefab at the root of your scene, call it OpenUrlReceiver.
    3. Attach a script to the OpenUrlReceiver, call it OpenUrlReceiver.cs. Put one method inside:
    public void ReceiveOpenUrl(string url)
    {
    Debug.Log(“Got an app open url: ” + query);
    }
    4.Make sure the Assets>Plugins>iOS contains the following files from this plugin:
    InAppBrowserViewController.mm
    InAppBrowserViewController.h
    iOSInAppBrowser.mm
    OrientationNavigationViewController.h
    OrientationNavigationViewController.m
    5. Create your own .mm file in the same place as those above called MyApp.mm and inside put the following obj c code:

    #import <UIKit/UIKit.h>
    #import “UnityAppController.h”
    #import “UI/UnityView.h”
    #import “UI/UnityViewControllerBase.h”

    @interface MyApp : UnityAppController
    – (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation;

    @end

    @implementation MyApp

    extern void UnitySendMessage(const char*, const char*, const char*);

    – (BOOL)application:(UIApplication*)app openURL:(NSURL*)url options:(NSDictionary<NSString*, id>*)options
    {
    const char* fullUrl = [[[url absoluteString] stringByRemovingPercentEncoding] UTF8String];

    UnitySendMessage(“OpenUrlReceiver”, “ReceiveOpenUrl”, fullUrl);

    return [super application:app openURL:url options:options];
    }

    6. Build your app to iOS and open in Xcode
    7. Run the app on a device.
    8. Open a browser to somewhere which will end up with a redirect flow back to your app, or go to this test url:https://universaldeeplinking.imaginationoverflow.com/test
    and enter a url your app expects: com.Company.ProjectName://hellothere
    9. See in the Xcode logs, the debug output:
    Got an app open url: com.Company.ProjectName://hellothere

    #1447
    JezPez
    Participant

    I forgot one step:

    Before you build the iOS project from Unity. (before step 6 above).
    You need to move the InAppBrowserBridge prefab into your scene at the root. (Assets/InAppBrowser/Prefabs/InAppBrowserBridge)

    #1451
    JezPez
    Participant

    Upon further investigation, most identity providers are deliberately blocking use of In-App browsers for Authentication because the default in app browser for iOS and Android is not secure.

    Read more here: https://auth0.com/blog/google-blocks-oauth-requests-from-embedded-browsers/

    As such, this plugin is not appropriate for OAuth interactive login purposes.

    The proper iOS way for authentication is to open a ASWebAuthenticationSession (iOS 12+) or SFAuthenticationSession (iOS 11):
    https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession
    https://developer.apple.com/documentation/safariservices/sfauthenticationsession

    Sadly there is no plugin out there which opens a secure browser so I guess I’m writing one!

    Cheers,

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.