React-native current URL and access to cookies

Source: Internet
Author: User

The previous introduction about React-native's running Helloword level, so the simple thing is not written, after all, the official web can be found.

Reactnative Official website: https://facebook.github.io/react-native/docs/getting-started.html

Reactnative Chinese web: http://reactnative.cn/docs/0.25/getting-started.html

After that I will share some of the react-native deep pits I have encountered in my work.

About ===========================

The acquisition of client-side cookies is a big pit.

1. Use three-party

Research reactnative Source Discovery, the framework does not implement the iOS Nshttpcookiestorage API, so search all over Baidu Google and Bing, finally found a buddy wrote third-party cookies tools:

Https://github.com/joeferraro/react-native-cookies

What I need to mention here is that I need to obtain a cookie not only in the form of a dictionary, but as a cookiesheader for HTTP requests, in the form of a string, which is obtained in OC in the following way:

Nsarray *cookies =*header = [Nshttpcookie requestheaderfieldswithcookies:cookies];

But there seems to be some problem with the original author's frame, so I wrote a pull request to access my Fork's project:

Https://github.com/rayshen/react-native-cookies

2. Get the current URL

This requires a combination of the WebView control to operate.

First we need to determine the current URL, and the current URL can be obtained from the event onnavigationstatechange that the WebView control binds to:

Onnavigationstatechange={this.onnavigationstatechange.bind (This)}

Onnavigationstatechange (navstate) {     console.log (navstate.url);     This.cururl = Navstate.url;  }

3. Obtain the URL of the cookie header:

Cookiemanager.getheader (This.cururl, (err, res) = {      Console.log (' Got Cookies for URL: ' + res. Cookies); })

4. All cookies obtained from the URL

Cookiemanager.get (' http://example.com ', (err, res) = = {  Console.log (res);})

  

 

React-native current URL and access to cookies

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.