Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use JailMonkey.canMockLocation() ? #4

Closed
KevinHu2014 opened this issue Aug 2, 2016 · 8 comments
Closed

How do I use JailMonkey.canMockLocation() ? #4

KevinHu2014 opened this issue Aug 2, 2016 · 8 comments

Comments

@KevinHu2014
Copy link

How do I use JailMonkey.canMockLocation() ?
Does it support RN 0.30 ?

I got undefined is not an object (evaluating 'this.props.navigator') error

Here's my code

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import JailMonkey from 'jail-monkey';

class RNmonkey extends Component {

  componentWillMount(){
   JailMonkey.canMockLocation();
  }
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

module.exports = RNmonkey;
@GantMan
Copy link
Owner

GantMan commented Aug 2, 2016

That's odd - I don't mention a navigator anywhere in this library. Are you sure you have cleaned your packager and cache?

I just created a brand new 0.30.0 app and implemented the following app, it worked fine:

import React, { Component } from 'react';
import JailMonkey from 'jail-monkey';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

class RNMonkey extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          IS JAIL BROKEN?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.isJailBroken().toString()}
        </Text>
        <Text style={styles.welcome}>
          CAN MOCK LOCATION?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.canMockLocation().toString()}
        </Text>
        <Text style={styles.welcome}>
          TRUST FALL?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.trustFall().toString()}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('RNMonkey', () => RNMonkey);

image

@KevinHu2014
Copy link
Author

I found out that base on the same code.
It works fine on iOS but gets errors on Android.
And I not sure how to clean packager and cache.
2016-08-03 7 56 12
2016-08-03 7 56 25

Did I miss something else?

@GantMan
Copy link
Owner

GantMan commented Aug 3, 2016

Is the Android code exactly the same? Can you copy and paste it?

@KevinHu2014
Copy link
Author

@GantMan
Yes ,exactly the same.
Here's my code

import React, { Component } from 'react';
import JailMonkey from 'jail-monkey';

import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

class Fuck extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          IS JAIL BROKEN?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.isJailBroken().toString()}
        </Text>
        <Text style={styles.welcome}>
          CAN MOCK LOCATION?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.canMockLocation().toString()}
        </Text>
        <Text style={styles.welcome}>
          TRUST FALL?
        </Text>
        <Text style={styles.instructions}>
          {JailMonkey.trustFall().toString()}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});
AppRegistry.registerComponent('Fuck', () => Fuck);

@KevinHu2014
Copy link
Author

@GantMan
Have you tried on Android?

@GantMan
Copy link
Owner

GantMan commented Aug 3, 2016

I know it works perfectly on Android in 0.27.2, I'll check on 0.30.0 now.

@GantMan
Copy link
Owner

GantMan commented Aug 3, 2016

I found your problem

here it is working on 0.30.0
image

If you use rnpm to link the library, it doesn't know about the update that happened in 0.29. rnpm actually is FAILING to link anything after 0.29.0, because it links the Activity in Java and not the Application (introduced in 0.29.0).

Looks like people will have to use react-native link if they are 0.29+. I'll add this to the README.

If you adjust your MainApplication.java to this, it will work for you:

package com.rnmonkey;

import android.app.Application;
import android.util.Log;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.gantix.JailMonkey.JailMonkeyPackage;

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new JailMonkeyPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
  }
}

@KevinHu2014
Copy link
Author

@GantMan
Thanks for the help and this great Library.
I'm able to run on Android now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants