0

In Android I can achieve it using this method. Can anyone tell me how to achieve this in iOS using UIWebView or WKWebView?

@JavascriptInterface
    public boolean RememberMe(String UserData) {
        String str = UserData.replace("\\", "");
        str = str.substring(1, str.length() - 1);

        try {
            clsDBHelper DB = new clsDBHelper(MainActivity.this);
            JSONArray StoreData = DB.GetQueryNew("Select * from UserInfo", null);
            if (StoreData == null) {
                JSONArray Obj = new JSONArray(str);
                Integer TransID = Obj.getJSONObject(0).getInt("TransID");
                Integer OPID = Obj.getJSONObject(0).getInt("OPID");
                Integer ProviderID = Obj.getJSONObject(0).getInt("ProviderID");
                Integer CustomerID = Obj.getJSONObject(0).getInt("CustomerID");
                Integer CompID = Obj.getJSONObject(0).getInt("CompID");
                String UserID = Obj.getJSONObject(0).getString("UserID");
                String Password = Obj.getJSONObject(0).getString("Password");
                String RegMoblileNo = Obj.getJSONObject(0).getString("RegMoblileNo");
                String RegEmialID = Obj.getJSONObject(0).getString("RegEmialID");
                Integer Verifyflag = (Obj.getJSONObject(0).getBoolean("Verifyflag") == true ? 1 : 0);
                Integer IsActive = (Obj.getJSONObject(0).getBoolean("IsActive") == true ? 1 : 0);
                String OTP = Obj.getJSONObject(0).getString("OTP");
                String OTPTimeStamp = Obj.getJSONObject(0).getString("OTPTimeStamp");
                String OperatorID = Obj.getJSONObject(0).getString("OperatorID");
                DB.ExeNonScalerQuery("INSERT INTO UserInfo(TransID,OPID,ProviderID,CustomerID,CompID,UserID,Password,RegMoblileNo,RegEmialID,Verifyflag,IsActive,OTP,OTPTimeStamp,OperatorID)values("
                        + TransID + "," + OPID + "," + ProviderID + "," + CustomerID + "," + CompID + ",'" + UserID + "','" + Password + "','" + RegMoblileNo + "','" + RegEmialID + "'," + Verifyflag + "," + IsActive + ",'" + OTP + "','" + OTPTimeStamp + "','" + OperatorID + "')");
            }
            DB.CloseDB();
        } catch (JSONException e) {
            e.printStackTrace();
            clsDBHelper DB = new clsDBHelper(MainActivity.this);
            DB.GetQueryNew("Delete  from UserInfo", null);
            DB.CloseDB();
        }
        return true;
    }

When I login to the app, the RememberMe function in JavaScript sends me a string which I need to save in a plist.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
jakir hussain
  • 316
  • 2
  • 18

2 Answers2

1

On iOS, you typically handle this with WKScriptMessageHandler: https://developer.apple.com/documentation/webkit/wkscriptmessagehandler?preferredLanguage=occ

Essentially, you use WKWebView, then call this method in JavaScript:

window.webkit.messageHandlers.notification.postMessage( "message" );

And then in your app code, implement a WKScriptMessageHandler, which you hook into your web view, and use it to receive the message:

func userContentController( 
    userContentController: WKUserContentController, 
    didReceiveScriptMessage message: WKScriptMessage) {
    // do stuff
}

You can read about it in detail on NSHipster: http://nshipster.com/wkwebkit/

Geoffrey Wiseman
  • 5,459
  • 3
  • 34
  • 52
  • func webViewDidFinishLoad(webView : UIWebView) { WebView.stringByEvaluatingJavaScript(from:"LoginByMobileApp()") } how to implement it using WKWebView – jakir hussain Oct 16 '17 at 07:15
  • 1
    It's probably better to ask that as a question rather than on a comment to this answer, but ... something like this seems like the direction you'd want to go in: https://stackoverflow.com/questions/25504481/wkwebview-content-loaded-function-never-get-called – Geoffrey Wiseman Oct 16 '17 at 22:00
0

Seems like you are getting array from that "remmeber" method , So save 1st element in var and then test of its type . If its json then retrieve data as you do for NSDictionary

Jitendra Tanwar
  • 249
  • 2
  • 11