Javascript implementation in UIWebView

Managing three UITextfields along with a submit button can be challenging when dealing with validations. However, the real challenge arises when trying to send the text from these fields to JavaScript for credential validation before transitioning to the next view.

- (IBAction) login: (id) sender
{
    if (enableLogin == YES) {
      // [self loadNextView]; 
    }
}

-(void)loadNextView {

appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
if (webViewDidFinishLoadBool == YES) {
    [appDelegate loginUser: txtfield1.text];
    NSLog(@"loadNextView called");
} else NSLog(@"loadNextView not called");
}


-(void)sendToJS {
//    NSString* htmlPath = [[NSBundle mainBundle] pathForResource:@"pathtohtml" ofType:@"html"];
//    NSString* appHtml = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];
//    NSURL *baseURL = [NSURL fileURLWithPath:htmlPath];
//    [self.webview loadHTMLString:appHtml baseURL:baseURL];
    NSURLRequest *myReq = [NSURLRequest requestWithURL:
                          [NSURL URLWithString:
                          [NSString stringWithFormat:@"pathtohtml.html"]]];
    [self.webview loadRequest:myReq];

if (self.webview != nil) {
    jsCallBack = [NSString stringWithFormat: @"loginUser.login('%@', '%@', '%@');", txtfield1.text, txtfield2.text, txtfield3.text];
}
}

-(void)webViewDidStartLoad:(UIWebView *)webView {
    NSLog(@"js loaded");
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
        [self.webview stringByEvaluatingJavaScriptFromString:jsCallBack];
}

  - (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType {

    NSString *requestString = [[request URL] absoluteString];
    NSArray *components = [requestString componentsSeparatedByString:@":"];

    if ([components count] > 1 &&
        [(NSString *)[components objectAtIndex:0] isEqualToString:@"jscall"]) {
        if([(NSString *)[components objectAtIndex:1] isEqualToString:@"myapp"])
        {
            NSString *urlString =  (NSString *)[components objectAtIndex:2];

            NSLog(@"URL STRING %@", urlString);
            if ([urlString  isEqual: @"OK"]) {
                globalValue = YES;
                webViewDidFinishLoadBool = YES;
                [self loadNextView];
                NSLog(@"is called");
            } else NSLog("is not called");
        }
        return NO;
    }
    return YES;
}

Despite thorough testing and setting delegates correctly, the functionality seems to be unreachable. Even a simple alert generating function failed to work as expected.

Please note that the folder structure cannot be altered; Obj C classes are in one folder while HTML and JS files reside in separate locations.

Answer №1

Whenever the variable "enableLogin" turns true, I will refresh the webview.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for consolidating multiple JavaScript files from various directories into one single file?

I am currently working on a project that involves multiple JavaScript files stored in various folders. My goal is to combine them all into a master.js file. The project structure looks like this: /dist/js/master.js <-- Output file /src/bootstrap-untou ...

Tips on retrieving data from an http request in Angular 2 after it has been successfully made

Consider this example function: getSessionInfo() { this._http.get(someCorrectUrlHere) // It is unclear what this map function does .map(res => res.json()) // It is unclear what this subscribe function does .subscribe( data = ...

Is it possible to conduct a feature test to verify the limitations of HTML5 audio on

Is there a way to detect if volume control of HTML5 audio elements is possible on iOS devices? I want to remove UI elements related to the volume if it's not alterable. After referring to: http://developer.apple.com/library/safari/#documentation/Aud ...

Adjust the output number in a JavaScript BMI calculator to the nearest whole number when using the

Hey there, I'm currently working on a beginner project and could use some assistance. My project involves creating a basic BMI calculator using metric units, but I seem to be encountering issues with rounding numbers. Here is a snippet of my code: var ...

What is the best way to organize data subsets in Firebase?

I am currently working on saving data from multiple sections within my webapp. One section involves storing employee information, while the other deals with employer group information. However, when I save this data in Firebase, it all gets organized by ID ...

Struggling to understand the relationship between SetInterval and closures

Is there a way to continuously update the contents of a div using setInterval I found inspiration from this question on Stack Overflow: How to repeatedly update the contents of a <div> by only using JavaScript? However, I have a couple of questions ...

Switch between TrackBall and FlyControls in threejs to change the type of controls being used

My goal is to implement two different control modes in my project: a free "flying" mode and an object-centered (trackball) mode. I want to seamlessly switch between them with the press of a button. Initially, I experimented with TrackBallControls and FlyC ...

Using jQuery to create a captivating Parallax Effect on your website's background image

Hey there! I have a div with the class 'section' that serves as a key element on my website. It has a background image set using the following CSS: .section-one { width: 100vw; height: 100vh; background-image: url(images/outside-shot ...

The minimum and maximum limits of the Ionic datepicker do not function properly when selecting the month and day

Recently, I have been experimenting with the Ionic 2 datepicker. While the datepicker itself works perfectly fine, I've run into some issues when trying to set the min and max properties. <ion-datetime displayFormat="DD-MM-YYYY" [min]="event.date ...

Updating the image source URL dynamically inside a division within a script using JavaScript

I'm attempting to insert a dynamic URL within an img src tag. Below is my HTML and Script code. When a tab is clicked, a GET HTTP Method is called, which responds with an image URL. I want to use this image URL in the img src field. HTML Code ...

Issues with HTML marquee not functioning properly post fadeIn()

I am attempting to create a progress bar using the HTML marquee element. When the user clicks submit, I want to fadeIn the HTML marquee and fadeOut with AJAX success. However, when I click the submit button, the marquee does not fadeIn as expected. Here is ...

No response text returned from the local Ajax request

Currently, I am facing a challenge while attempting to send an ajax call from the client to my server containing data related to an input parameter. The issue is that although I can view the data in my server's console, it does not display in the brow ...

What is the best way to invoke the draw() method of Datatables with Ajax?

In my Django application, I am working on implementing the draw() method from datatables using AJAX. Both datatables and AJAX are functioning properly. However, whenever I create a new object and call the draw() method to refresh the table with the newly c ...

Tips for expanding third-party classes in a versatile manner using Typescript

tl;dr: Seeking a better way to extend 3rd-party lib's class in JavaScript. Imagine having a library that defines a basic entity called Animal: class Animal { type: string; } Now, you want to create specific instances like a dog and a cat: const ...

Is it possible to temporarily change the state and then revert it back to its original state by utilizing settimeout?

I'm trying to temporarily set the value to true for one second and then revert it back to false using setTimeout, but I'm encountering an issue with my code. Here's what I have so far: const [value, setValue] = useState(false) const handleCl ...

What is the true functionality of iOS's performSelector:withObject:withObject:?

Can you tell me the difference between selectors that have the same argument types but in a different order? I have two selectors with the same argument types. - (void)methodWithCallBack:(void(^)(void)) cb double:(double)value { NSLog(@"%s %f", __PRET ...

How can you verify renewable subscriptions within iOS 6's in-app purchases?

I'm currently working on an app that provides a 30-day subscription for premium features within the application. While I have set up in-app purchases (consumables) and all seems to be running smoothly, I am struggling to find clear guidance on how to ...

Utilize JavaScript to assign a value to a concealed Pardot field

Recently, I've been working on setting a hidden Pardot field within an iframe. Oddly enough, when I manually input the query selector in my Chrome console, I successfully locate the element. However, when running this code snippet (embedded in the &l ...

Adjusting the width of innerHtml within a React router link to match the parent element's width

My current challenge involves a table where a cell is represented as a link. Within this setup, I am incorporating html content into the text of the link: <TableCell align="left" classes={{root: classes.cellPadding}}> <Link className={classes.l ...

What is the cost associated with using the require() function in an Express.js application?

I have a web application built with Express.js that serves one of my domains. The structure of the app.js file is as follows: var express = require('express'); var app = express(); // and so on… To incorporate one of my custom functions in t ...