viestat / react-native-spotify

A native module that allows you to use the Spotify SDK API with react-native
MIT License
108 stars 23 forks source link

NativeModule Failure #5

Closed digitaldavenyc closed 8 years ago

digitaldavenyc commented 8 years ago

Before I get into the issue, I want to thank you for making this library!

I have followed the instructions on the README and Spotify's as well to setup the project. Unfortunately, when I call SpotifyAuth.setClientID I receive an error Cannot read property 'setClientID' of undefined.

It seems that SpotifyAuth is not importing as a NativeModule for some reason.

I will admit I have no experience with native modules and perhaps I am doing something wrong but I did follow the directions and place SpotifyAuth.m, SpotifyAuth.h, SpotifyLoginViewController.m and SpotifyLoginViewController.h in the ios directory of the project. I also cleaned my build folder and rebuilt the project just to be safe and that did not fix the issue either.

Here is the code for the player file I have started to develop

import React, { Component } from 'react';
import { View, Text, StatusBar, Dimensions, TouchableOpacity, StyleSheet, Image } from 'react-native';
import { NativeModules } from 'react-native';

var SpotifyAuth = NativeModules.SpotifyAuth;

var { width, height } = Dimensions.get('window');

var styles = StyleSheet.create({
    button: {
        justifyContent: 'center',
        marginTop: 90,
        alignItems: 'center',
        width: 250,
        height: 45,
        borderRadius: 64
    }
});

export default class Player extends Component {
    login() {
        SpotifyAuth.setClientID('xxxxxxx','discovery://callback', ['streaming'], (error) => {
            if(!error){
                this.props.navigator.replace({component: logInSuccess, title: 'Success'});
            } else {
                console.log('error:', error);
            }
        });
    }

    render() {
        return (
            <View style={{backgroundColor: '#171717', width: width, height: height}}>
                <StatusBar barStyle='light-content' />
                <TouchableOpacity style={styles.button} onPress={() => this.login()}>
                    <Image resizeMode={'contain'} style={styles.image} source={require('../../images/player/login-button.png')} />
                </TouchableOpacity>
            </View>
        )
    }
}
screen shot 2016-09-19 at 1 27 16 am
digitaldavenyc commented 8 years ago

I apologize, this was a n00b error on my part.

You have to drag

into the XCode project in addition to copying them to the project ios directory. You might want to update the docs on this for other developers.