2016-12-18 76 views
0

我正在使用反應本機和此庫在相機上拍攝圖像的屏幕截圖:https://github.com/gre/react-native-view-shot將原生相同的快照反應到相機膠捲

我的項目編譯正確,我可以點擊我的「截圖」按鈕,它返回臨時文件路徑的URI。

2016-12-17 20:02:50.049 [info][tid:com.facebook.react.JavaScript] 
    'Image saved to ', '/private/var/mobile/Containers/Data/Application/C46841FC-C985-4396-A8DE-9A8C3CD7A9B8/tmp/ReactNative/C06F2B55-C390-495C-A4C5-63988C1CD374.jpg' 

然而,當我試圖將圖像保存至相機膠捲,我得到以下錯誤:

[info][tid:com.facebook.react.JavaScript] 
    'error save: ', [TypeError: undefined is not an object (evaluating 'RCTCameraRollManager.saveToCameraRoll') 

我的設置看起來是這樣的:

import React, { Component } from 'react'; 
import {takeSnapshot} from 'react-native-view-shot'; 
import { 
    CameraRoll, 
    Text, 
    View 
} from 'react-native'; 
import Camera from 'react-native-camera'; 

export default class CameraView extends Component { 
    constructor() { 
     this.camera = null; 
    } 
    setCamera(ref) { 
     this.camera = ref; 
    } 
    capture() { 
     takeSnapshot(this.camera, {format, quality}) 
      .then(
       uri => { 
        console.log("Image saved to ", file); 
        CameraRoll.saveToCameraRoll(uri, 'photo'); 
       } 
      ) 
      .catch(error => console.log('error save: ', error)); 
    } 
    render() { 
     return (
      <View> 
       <Camera ref={ref => this.setCamera(ref)}> 
        <Text onPress={() => this.capture()}> 
         take screenshot 
        </Text> 
       </Camera> 
      </View> 
     ); 
    } 

當我遠程調試瀏覽器中的js錯誤,我得到以下錯誤:

TypeError: Cannot read property 'saveToCameraRoll' of undefined 
    at Function.saveToCameraRoll (CameraRoll.js:159) 
    at CameraView.js:71 
    at tryCallOne (core.js:37) 
    at core.js:123 
    at JSTimers.js:100 
    at Object.callTimer (JSTimersExecution.js:95) 
    at Object.callImmediatesPass (JSTimersExecution.js:199) 
    at Object.callImmediates (JSTimersExecution.js:214) 
    at MessageQueue.js:214 
    at guard (MessageQueue.js:46) 

看來,我已經聯繫是iOS的需要適當的庫,但我仍然收到上述錯誤:

xcode

爲什麼會CameraRoll在這種情況下是不確定的?

回答

0

我其實沒有libRCTCameraRoll.a正確的二進制鏈接。一旦我這樣做,這個錯誤就停止了。

相關問題