Native vs HTML5

Source: Internet
Author: User

has driven the wide application of HTML5 technology a little exaggerated, but it did fire a bit.

Learn how iOS interacts with H5 now.

Part-one :

First, the principle

1.h5 to interact with iOS, first build Webviewbridge, communication bridge;

2. The second is the response of both parties.

A. First register the name of a response on the H5 side.

B.oc can call H5 by this name.

C.oc send a message to H5 in two cases, one is to require H5 to return parameters, and the other is to not require H5 to return data

Part-two

Second, use

The more useful third library Webviewjavascriptbridge

First step: register a UIWebView

uiwebview* WebView = [[UIWebView alloc] initwithframe:self.view.bounds];

[Self.view Addsubview:webview];

Step Two: Register "bridge"
-(void) Viewdidload {
if ( Self.bridge = = nil) {return;} [Webviewjavascriptbridge enableLogging]; Self.bridge = [Webviewjavascriptbridge bridgeforwebveiw:webviewdelegate : Self handler:^ (id data, Wvjbresponsecallback responsecallback) {
NSLog (@ "OBJC received message from JS:%@", data); }

Responsecallback (@ "Response for message from OBJC"); }];
}

The third step: JS Call oc Method

[_bridge Registerhandler:@ "Testobjccallback" handler:^ (ID data, Wvjbresponsecallback responsecallback) {        NSLog (%@ ", data);        Responsecallback (@ "Response from Testobjccallback");}];    

Fourth step: OC Call JS method

[_bridge callhandler:@ "Testobjccallback" Data:data responsecallback:^ (ID response) {

Response (@ "response from Testobjccallback");

}

Fifth:

No parameter return

[_bridge Send: @ "This is a message from OC"];

Returned with a reference

[_bridge send:@ "This a message from OC, please answer the message when u see it" responsecallback (^id response) {

NSLog (@ "The answer from JS");

}];

Native vs HTML5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.