Search code examples
iosfacebookwebviewcodenameonesfsafariviewcontroller

Codename one. Log in with Facebook using Webview component


My cn1 app incorporates loggin in with Facebook and Google+. When the doLogn() is called on Iphone, A Safari page is opened which allows the user to enter their credentials for Facebook or Google respectively. The problem I am facing is that my app has just been rejected by apple because the user is taken out of the app and into safari in order to log in with Facebook or Google and this, according to apple, provides "poor user experience". Apple recommended that I use the Safari View Controller API which allows the display of a URL and inspection of the certificate from an embedded browser in an app so that customers can verify the webpage URL and SSL certificate to confirm they are entering their sign in credentials into a legitimate page.

I notice that Codename one has a WebView component. However I'm not sure if it's possible to open the url in Webview instead of Safari when I call the doLogin(). If it is. How do I achieve this and is Web View the right component to use? Or will I need to use the Safari View Controller API, if so, how do I add this api to my cn1 project, is it even possible?

I would recommend that codenameone incorporate this into their Facebook and Google login features to prevent any future users from getting rejected by the app store.

It appears that this happens automatically on Native Iphone apps - Safari web view opening when logging to FB through iOS 9. For IOS should I try to implement a native Facebook log in then? If so. Where do I start?

final Login fb = FacebookConnect.getInstance();
    fb.setClientId("XXXXXXXXXXXXXX");
    fb.setClientSecret("XXXXXXXXXXXXX");
    fb.setRedirectURI("http://www.mibrandapp.com");
    FaceBookAccess.setPermissions(new String[]{"id", "name", "first_name", "last_name"});
    fb.setScope("id");
    fb.setCallback(new LoginCallback() {
        @Override
        public void loginFailed(String errorMessage) {
            Dialog dg = new Dialog();
            dg.setTitle("Login failed");
            dg.show();
        }

        @Override
        public void loginSuccessful() {
            ....
        }
    });
    //fb.doLogin();
    fb.nativelogin();

Solution

  • Currently the Codename One build server uses Facebook IOS SDK 4.4, which uses the default behaviour of opening the Facebook app to authenticate - if installed - and the Safari app if it is not installed.

    If you switch to the "iphone_new" build target (which will soon be standard) it uses the newer Facebook IOS SDK 4.12, which will (by default) handle the authentication inside a web view in your app.

    Running some tests on this approach, I found that, on iOS 9, you need to add the following to your ios.plistInject build hint:

    <key>LSApplicationQueriesSchemes</key><array><string>fbauth2</string></array>

    I have just committed a change that will include this automatically so after the next server update (probably on Friday), it will just work without this build hint.

    UPDATE June 14, 2016

    I have just updated this in SVN so that it will use IOS SDK 4.12 by default with will resolve this issue without having to make any changes. The server will be updated Friday - after which you should be able to just send your build (with no special build hints) and it will work.