@icehunter/react-native-play-licensing
v1.0.0
Published
Adds [Client-Side License Verification](https://developer.android.com/google/play/licensing/client-side-verification) to React Native applications. Works on both Android and iOS, but only verifies licenses on Android.
Downloads
6
Readme
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; // <--- import public class MainApplication extends Application implements ReactApplication { ...... @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), ...... new PlayLicensingPackage(), // <--- add package ); } ...... }
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);
}, []);
// do something if app is not licensed
// ...
}
API
verify(BASE64_PUBLIC_KEY, STRING_FOR_SALT)
PlayLicensing.verify(BASE64_PUBLIC_KEY).then((licensed) => {
if (licensed === true) {
// app was purchased from Google Play
} else if (licensed === false) {
// app was not purchased from Google Play
} else {
// verification failed, retry later
}
});