Home >Web Front-end >JS Tutorial >Interaction between native iOS and js
This time I will bring you the interaction between native iOS and js. What are the precautions 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 thecookie value is used to identify the user's identity.
Speaking of cookie values, I think it is necessary to mention jssessionid. From the Internetquery I 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; 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 ios7JavaScript Core, first we introduce this class and initialize a JSContext object.
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 topass the value .
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 delegateFor example, to interact with the web natively and call up a local 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!