{"id":108197,"date":"2020-05-31T01:46:46","date_gmt":"2020-05-30T17:46:46","guid":{"rendered":"http:\/\/4563.org\/?p=108197"},"modified":"2020-05-31T01:46:46","modified_gmt":"2020-05-30T17:46:46","slug":"%e5%9c%a8-ios-%e4%b8%8a%ef%bc%8c-react-native-%e8%bf%9c%e7%a8%8b-gif-%e5%9b%be%e7%89%87%e4%bf%9d%e5%ad%98%e5%88%b0%e7%9b%b8%e5%86%8c%e5%90%8e%e5%8f%98%e6%88%90%e4%ba%86%e9%9d%99%e6%80%81%e5%9b%be","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=108197","title":{"rendered":"\u5728 iOS \u4e0a\uff0c React Native \u8fdc\u7a0b GIF \u56fe\u7247\u4fdd\u5b58\u5230\u76f8\u518c\u540e\u53d8\u6210\u4e86\u9759\u6001\u56fe\u7247"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u5728 iOS \u4e0a\uff0c React Native \u8fdc\u7a0b GIF \u56fe\u7247\u4fdd\u5b58\u5230\u76f8\u518c\u540e\u53d8\u6210\u4e86\u9759\u6001\u56fe\u7247               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xyxc0673 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6700\u8fd1\u6709\u4e2a\u9700\u6c42\uff0c\u9700\u8981\u628a\u670d\u52a1\u5668\u4e0a\u7684 GIF \u56fe\u7247\u4fdd\u5b58\u5230\u7cfb\u7edf\u76f8\u518c\u4e2d\uff0c\u4f46\u662f\u6211\u5728\u5c1d\u8bd5\u4e86\u51e0\u79cd\u65b9\u5f0f\u540e\uff0c\u53d1\u73b0\u4fdd\u5b58\u540e\u7684 GIF \u56fe\u7247\u90fd\u53d8\u6210\u4e86\u9759\u6001\u56fe\u7247\u3002<\/p>\n<p>\u6211\u65b0\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684 RN \u9879\u76ee\u6765\u6a21\u62df\u8fd9\u6837\u7684\u60c5\u51b5<\/p>\n<pre><code>\"dependencies\": {     \"@react-native-community\/cameraroll\": \"^1.7.2\",     \"react\": \"16.11.0\",     \"react-native\": \"0.62.2\",     \"react-native-fs\": \"^2.16.6\",     \"rn-fetch-blob\": \"^0.12.0\"   } <\/code><\/pre>\n<p>\u5c1d\u8bd5\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f<\/p>\n<ul>\n<li>\u76f4\u63a5\u4f7f\u7528 cameraroll \u4fdd\u5b58\u5230\u76f8\u518c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u662f\u4e0d\u884c\u7684\uff0c\u5728 issues \u4e2d\u6709\u4eba\u63d0\u5230\u8fc7<br \/> CameraRoll.saveToCameraRoll saves animated gif as static images<\/li>\n<\/ul>\n<pre><code>const img = 'https:\/\/i.loli.net\/2020\/05\/28\/YKaCdO1pexuThbN.gif' CameraRoll.saveToCameraRoll(img); <\/code><\/pre>\n<ul>\n<li>react-native-fs \u4e0b\u8f7d\u56fe\u7247\u5230\u4e34\u65f6\u76ee\u5f55\uff0c\u518d\u4fdd\u5b58\u5230\u76f8\u518c\u4e2d<\/li>\n<\/ul>\n<pre><code>const img = 'https:\/\/i.loli.net\/2020\/05\/28\/YKaCdO1pexuThbN.gif' const storeLocation = `${RNFS.TemporaryDirectoryPath}`; const pathName = `${new Date().getTime()}_babycam_moji.gif`; const downloadPath = `${storeLocation}${pathName}`; const ret = RNFS.downloadFile({   fromUrl: img,   toFile: downloadPath, }); ret.promise.then((res) =&gt; {   console.log('res', res);   if (res &amp;&amp; res.statusCode === 200) {     const promise = CameraRoll.saveToCameraRoll(       `file:\/\/${downloadPath}`,     );     promise.then(() =&gt; {});   } else {   } }); <\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528 rn-fetch-blob \u4e0b\u8f7d\u56fe\u7247\u5230\u4e34\u65f6\u76ee\u5f55\uff0c\u518d\u4fdd\u5b58\u5230\u76f8\u518c\u4e2d<\/li>\n<\/ul>\n<pre><code>RNFetchBlob.config({appendExt: 'gif', fileCache: true})   .fetch('GET', img)   .then((res) =&gt; {   console.log('res', res.path());   CameraRoll.saveToCameraRoll(res.path()); }); <\/code><\/pre>\n<p>\u4ee5\u4e0a\u7684\u65b9\u6cd5\u6211\u90fd\u5c1d\u8bd5\u8fc7\uff0c\u4f46\u4fdd\u5b58\u540e\u7684 GIF \u56fe\u7247\u8fd8\u662f\u53d8\u6210\u9759\u6001\u56fe\u7247\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1803930\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tanranran <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bd5\u8bd5\u7528\u4e09\u65b9\u8f6f\u4ef6\u67e5\u770b\uff0c\u770b\u770b\u80fd\u4e0d\u80fd\u64ad\u653e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1803931\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xyxc0673 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @tanranran \u6211\u7528 Airdrop \u4f20\u5230\u7b14\u8bb0\u672c\u4e0a\uff0c\u8fd8\u662f\u4e00\u6837\uff0c\u9759\u6001\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 iOS \u4e0a\uff0c React Na&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/108197"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=108197"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/108197\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108197"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}