Explain in detail the interaction between JS and app native controls

"Hot update" and "hot deployment" believe that children's shoes with hybrid development must be familiar, so how can app avoid being released in the app store every time it is upgraded? The concept of hybrid development is used here. It is particularly important for e-commerce websites. It is impossible to release a current version every time an activity is released. Of course, this is OK for Android, but what about IOS? The audit time of Apple App store is basically 1 ~ 2 weeks, which is too long for a promotion. Hybrid development can just solve this problem. The basic principle is to realize the main structure of APP through native controls and develop the corresponding pages with the help of H5. In this way, each release activity only needs to be published on the server side, so that all installation users can view the latest activities without upgrading. Today, let's share how to realize the interaction between JavaScript and app native controls.

1、 First, let's introduce the interaction between JS and Android. First, let's take a look at the directory structure of Android project:

Jsobject.java file encapsulates the method of JS calling Android native controls; Mainactivity.java is the encapsulation of calling WebView control to load web pages and calling JS methods; Test.html is the HTML page we loaded. Next, let's look at the implementation:

MainActivity.java

Configuration file of the page (activity_main. XML)

JSObject.java

HTML pages loaded:

Here, because you need to implement a call making function, you need to add the call making permission in the androidmanifest.xml file:

<uses-permission android:name="android.permission.CALL_PHONE" />

Of course, the page loaded here is a local page. When loading a network page, you need to add the requested network permission:

<uses-permission android:name="android.permission.INTERNET" />

Well, the knowledge of mutual calling between JS and Android native controls is introduced. Finally, the Deml download address is attached: http://pan.baidu.com/s/1eSza8Pc

2、 JS interacts with IOS natively. The development language here is swift language, version 2.2. First, the project directory structure:

ViewController.swift

test.html

Well, the main contents of mutual calls between JS and IOS native controls are shared. Deml download address: https://pan.baidu.com/s/1gfJXr83

Here, the knowledge about the calling between JS, Android and IOS native controls is shared. Welcome to leave a message for discussion and learn from each other.

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>