Interaction between native iOS and js

php中世界最好的语言
Release: 2018-03-26 09:13:30
Original
2500 people have browsed it

This time I will bring you the interaction between native iOS and js. What are theprecautions for the interaction between native iOS and js? The following is a practical case, let’s take a look.

The first one: About automatic login. If you log in to the web page from the native app, you can log in directly to the web page without entering a password within a certain period of time. To implement this function, the server needs to identify the user's identity, and the

cookievalue is used to identify the user's identity.

Speaking of cookie values, I think it is necessary to mention js

sessionid. From the InternetqueryI learned that this jssessionid can be obtained through the first login webpage (currently I have not verified how to obtain it), but in order to reduce the burden on us, our backend wrote an interface for We get the jssessionid and return it to our mobile terminal, which is useful when we save cookies locally.

Before loading the web, save the cookie value. Before saving the cookie value, you need to clear the last saved cookie;

Interaction between native iOS and js

Interaction between native iOS and js

After doing this work, let’s talk about the interaction with js:

First of all, how does js call the oc method? Here we will talk about a new api launched in ios7

JavaScriptCore, first we introduce this class and initialize a JSContext object.

Interaction between native iOS and js

After initializing the JSContext object, we tell the web side through a model which method of ours to call, what the method is called, and how to

pass the value.

Interaction between native iOS and js

Interaction between native iOS and js

First explain JavaScriptObjectiveCDelegate, which is similar to the proxy we usually inherit from NSObject. The difference from the proxy we usually use is that it inherits from JSExport does not need to set the delegate

attributeor implement the proxy method. Because we need to implement these so-called proxy methods in .m of the model class.

For example, to interact with the web natively and call up a local photo album:

Interaction between native iOS and jsgoCamera is the
eventmethod agreed upon by you and h5. When the user When you click the album button on the web side, you can call the goCamera method. Then our iOS native app can use delegate or monitoring to carry out the operation of calling up the photo album.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to sort according to the key value size of the array

Laravel implements a multi-user authentication system

Generate intricate (tilt, sinusoidal interference line, paste, rotation verification) verification code

The above is the detailed content of Interaction between native iOS and js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!