react native same snapshot to camera roll

1.5k views Asked by At

I'm using react native and this library to take a screenshot of an image over the camera: https://github.com/gre/react-native-view-shot.

My project is compiling correctly and I am able to click on my "take screenshot" button which does return a uri of the temporary file path.

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'

However, when I try to save the image to the camera roll, i get the following error:

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

my setup looks something like this:

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>
        );
    }

When I remotely debug the js error in the browser, I get the following error:

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)

It seems that I have linked the appropriate Libraries that iOS requires but am still getting the error above:

xcode

Why would CameraRoll be undefined in this situation?

1

There are 1 answers

0
hellatan On

I actually didn't have the libRCTCameraRoll.a binary linked properly. Once I did that, this error stopped.