React Native Play Licensing
Adds Client-Side License Verification to React Native applications. Works on both Android and iOS, but only verifies licenses on Android.
Installing
npm install react-native-play-licensing
Linking Native Dependencies
Automatic Linking
react-native link react-native-play-licensing
Manual Linking
-
In android/settings.gradle
...
include ':react-native-play-licensing'
project(':react-native-play-licensing').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-play-licensing/android')
-
In android/app/build.gradle
...
dependencies {
...
implementation project(':react-native-play-licensing')
}
-
Register module in MainApplication.java
import com.github.icehunter.playlicensing.PlayLicensingPackage;
public class MainApplication extends Application implements ReactApplication {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
......
new PlayLicensingPackage(),
);
}
......
}
Usage
To use the react-native-play-licensing package in your codebase, use the PlayLicensing module:
import PlayLicensing from 'react-native-play-licensing';
export default function (App) {
const [licensed, setLicensed] = useState(null);
useEffect(() => {
PlayLicensing.verify('MIIBIjANBgkqhkiG...').then(setLicensed);
}, []);
}
API
verify(BASE64_PUBLIC_KEY, STRING_FOR_SALT)
PlayLicensing.verify(BASE64_PUBLIC_KEY).then((licensed) => {
if (licensed === true) {
} else if (licensed === false) {
} else {
}
});