iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 7
0
Mobile Development

ReactNative 懶人開發之路,薪水小偷練成日記(X系列 第 7

[Day:6] (σ′▽‵)′▽‵)σ 你看看你,我都用手機在Bar發文

回顧昨天,戰友們陸續出現人在江湖身不由己,沒有電腦可以發文的症狀

https://ithelp.ithome.com.tw/upload/images/20200920/20104220mrSjAyqnf5.png

昨天發現了一串神秘代碼....

userAgent={"User-Agent: Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"}

看來只要用大螢幕裝置或是更改 userAgent 就可以成功進入編輯草稿呢XD

但是手機瀏覽器不支援啊QQ /images/emoticon/emoticon70.gif

所以...

廢話不多說,上圖上code
https://gist.github.com/CS6/fb817731b49425281bf2f7250dbf9b61

https://ithelp.ithome.com.tw/upload/images/20200920/201042204SURbRZG5G.png

今天要推坑各位客官的則是...

早些時間從 react-native-core 中移至 react-native-community 維護的

react-native-webview

基礎使用方法

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Dimensions,
} from 'react-native';
import { WebView } from 'react-native-webview';
export default class Card extends Component {
  constructor(props) {
    super(props);
  }
  render() {
    return (
      <WebView
       source={{ uri: 'https://ithelp.ithome.com.tw' }}
       style={{ marginVertical: 10, height: 400, }}/>
    );
  }
}

加入 Cookie 才能模擬登入

import React, { Component } from 'react';
import {
  StyleSheet,
  View,
  Dimensions,
} from 'react-native';
import { WebView } from 'react-native-webview';
export default class Card extends Component {
  constructor(props) {
    super(props);
    this.state = {
      MyCookie: null,
    };
  }
  render() {
    return (
      <WebView
        source={{
          source={{ uri: 'https://ithelp.ithome.com.tw' }}
          headers: {
            Cookie: this.state.testCookie + "",
          },
        }}
        style={{ marginVertical: 10, height: 400, }}
      />
    );
  }
}

加入 Cookie 才能模擬登入與更改 userAgent 才可以成功進入編輯草稿

(  ̄ 3 ̄)y


上一篇
[Day:5]]我還沒發文┌(;゚д゚)┘等等我啊~┌( • ̀ω•́ )┘┌( *´∀` )┘┌( • ̀ω•́ )┘┌|◎o◎|┘
下一篇
[Day:7] [設計師說] d(`・∀・)b 今晚,我想來點.......珍珠奶茶???Σ(°Д°;
系列文
ReactNative 懶人開發之路,薪水小偷練成日記(X31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言