Accessing an AngularJS controller method within an iOS UIWebView

I am currently facing an issue with my dashboard.html page and DashboardController.js in relation to UIWebview. I am attempting to call an AngularJS function from DashboardController.js within the UIWebview, but it seems to not be working.

Below is the code snippet that I have been trying on iOS:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *url = [request URL];
    NSLog(@"URL:%@",url);
    if (![Utility isInternetAvailable]) {
        return FALSE;
    }
    NSString *jsCallBack = [NSString stringWithFormat:@"DashboardController.test()"];
    NSString *response =  [webView stringByEvaluatingJavaScriptFromString:jsCallBack];
    NSLog(@"%@",response);
    return YES; // Return YES to ensure regular navigation functions as expected.
}

I also attempted without referencing the Controller after confirming that dashboard.html has loaded inside the UIWebview: NSString *jsCallBack = [NSString stringWithFormat@"test()"];

The test() function is defined within the scope of DashboardController.js:

function test (){
  alert('sendCredentialsToNativeApp');
}

Any help would be greatly appreciated. Thank you.

Answer №1

It is recommended to invoke the test() function when you have declared it without referencing the controller in your JS file. Keep in mind that this function can only be accessed once the page is fully loaded, as no methods from the controller can be called before complete loading.

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

Square Division, width set to match 100% of the height

I have been attempting to create a square shape that is responsive, with the width determined by the height of the element (100%). I personally think achieving this using CSS alone is not possible. The goal is for the square's width to match its heig ...

What is the best method for fetching data from PHP to display on my Angular page?

I am struggling to retrieve data from MySQL to display on my AngularJS page, using PHP as my server-side language. I can fetch the data from my PHP file but unable to render it on my page. If you have any alternative solutions, please let me know. Below i ...

Store information for the node application while it is running

I have a node application where I need to store data that will be accessible for user requests as long as the node app is running. I want to avoid recalculating or parsing it for each request, so I only do it once. I came across the following method, whic ...

React - warning - Avoid using <Link> outside of a <Router> context

Warning: Invariant failed: It is not recommended to use <Link> outside of a <Router> Encountering this while attempting to write a test for a component where test("renders post list div ", () => { const posts = [ { created: ...

Implementing OpenId Connect Authorization Code flow with AngularJS

I am currently seeking the most effective strategy for implementing the Open Id Authorization Code flow in Angular JS. While I have found examples of the Implicit flow to obtain temporary tokens like id_token and access_token, my goal is to acquire a long- ...

Determine if a draggable item is currently positioned over another element

In my body, there are several divs located: <div id="one"></div> <div id="two"></div> <div id="three"></div> All of these divs are draggable using jqueryUI: var $divs = $('#one, #two, #three'); $divs.draggab ...

Navigating through a jQuery array while utilizing the $.inArray method

Below is an example of my Array that I am working with, retrieved from a successful jQuery .post call: data = JSON.parse(data); $(".chk_permission_").each(function() { if ($.inArray($(this).val(), data)) { $(thi ...

What is the process for changing external CSS files?

I have been diving into AJAX through a couple of books, but I am still relatively new at it. All the resources I've come across offer examples of auto-populating search bars and asynchronous form validators. While those are valuable, they are not exac ...

A guide to printing a web page within an ion-view container

I am currently utilizing the Ionic Framework for my web application. Each page within the app is displayed using ion-view. I have a requirement to display graphs and possibly save them as PDF files. Below is a snippet of my code: <ion-view title="Repo ...

JavaScript Array Multiplication Theory

I am working with 2 arrays list1 = ["x","y"] list2 = [ ["5","6","7"],["20","21","22"]] My goal is to create an array of objects like this: [ {list1: x , list2: 5}, {list1: x , list2: 6}, {list1: x , list2: 7}, {list1: y , list2: 20}, {list1: y , l ...

Running a code from a plugin in Wordpress site

I am currently utilizing the "wp-video-lightbox" plugin for WordPress, which generates small floating boxes for my videos. I am interested in incorporating variables like http://www.example.com/?video3 to provide shortcuts similar to what YouTube offers. ...

Getting a property from an axios function within the Vue 'created' method - here's how

I am trying to implement the Axios interceptors to display a loader component while Axios is making a request. The issue I am facing is related to accessing the isLoading property within the Axios function. In my root component, I have set up these interce ...

The iframe on my WordPress website is not displaying at its full size as intended

Is it possible to embed a link to a website in WordPress that is responsive to different devices, such as desktops and phones with varying screen sizes? On desktops, it looks fine, but on phones, it gets cut off and does not adjust accordingly. Using padd ...

Looking to adjust image properties like brightness, contrast, and gamma in iOS? Learn how to do so by dragging sliders

Hey there, I've been trying to use GPUImagefilters to apply brightness on an image but unfortunately it's not working. I'm having trouble identifying where the issue lies. Here is my code: - (void)viewDidLoad { self.slider.hidden=YES; slide ...

Tips for utilizing Angular expression within the href attribute of Angular Strap's dropdown component

For a project, I am incorporating AngularJS along with the Angular Strap plugin. The page features a table where one of the columns consists of various links. Upon clicking a link, it triggers Angular Strap's dropdown menu to appear as a contextual m ...

Is there a way to access Yahoo mail inbox without the user interface?

Exploring various API search options and resources including SerpWow, SERP API, ProgrammableWeb API for Yahoo Search. Experimenting with API token authentication as well. ...

Navigating between pages using the sidebar component in Next.js/React.js - A beginner's guide

Here is a snippet from my app.js file: function MyApp({ Component, pageProps }) { return ( <ThemeProvider attribute="class"> <Context> <Sidebar> <Component> ...

Why does middleware get invoked multiple times in node.js when redirecting to a page using Expressjs?

Can you help me understand how middleware functions are invoked in an Express.js app? I have the following code snippet: // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jad ...

Can an object in Node.js be 'required' to have access to the global scope of the importing files?

I've been researching extensively to find out if this is achievable. According to my findings so far, it seems that it may not be possible. Within my main.js file, I have the following code snippet: var commands = require('./commands.js'); ...

send the value from the input field to the designated button - link the two buttons

My goal is to create a feature where users can click on a button within the map and open an external page in Google Maps with specific dimensions (500 X 600) and without the Menu bar, Tool bar, or Status bar. // Custom Button Functionality by salahineo ...