2015-10-17 105 views

回答

3

我有同樣的問題,我檢查反應本土CameraRoll API,它提供了一個靜態函數

static saveImageWithTag(tag, successCallback, errorCallback) 

幫助您將圖像保存至相機膠捲/畫廊。

1.首先,確保您的/node_modules/react-native/Libraries/CameraRoll/RCTCameraRoll.xcodeproj已正確鏈接到您當前的項目。如果不正確,則應首先按照此處的官方文檔進行操作。 (https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content

2.第二,讓你的圖像源做好準備。對我來說,我把它放在項目資產庫中。

3.像這樣編碼。在這種情況下,我在componentDidMount執行時保存圖像。 (這是我參考鏈接:https://thebhwgroup.com/blog/accessing-iphone-camera-roll-images-react-native

'use strict'; 
 

 
var React = require('react-native'); 
 

 
var { 
 
    CameraRoll, 
 
    View, 
 
} = React; 
 

 
var CameraRollTest = React.createClass({ 
 
    
 
    componentDidMount() { 
 
    CameraRoll.saveImageWithTag('YOUR_IMAGE_TAG/URI', function(data) { 
 
     console.log(data); 
 
    }, function(err) { 
 
     console.log(err); 
 
    }); 
 

 
    }, 
 
    render: function() { 
 
    return (
 
     <View> 
 
     </View> 
 
    ); 
 
    } 
 
}); 
 

 
module.exports = CameraRollTest;

+1

雖然此鏈接可以回答這個問題,最好是在這裏有答案的主要部件,並提供鏈接以供參考。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – Brody

+0

謝謝你,我在我的答案中添加了我的實現。 – Wei

相關問題