From 9e9f372988b2fe003d49cc27c5da0530e1a1ce64 Mon Sep 17 00:00:00 2001 From: Atul R Date: Sat, 21 Apr 2018 15:18:48 +0530 Subject: [PATCH] Added new method to extract play store version --- .../com/masteratul/RNAppstoreVersionCheckerModule.java | 9 +++++++-- src/versionChecker.android.js | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/masteratul/RNAppstoreVersionCheckerModule.java b/android/src/main/java/com/masteratul/RNAppstoreVersionCheckerModule.java index f511fdf..f8ee2ba 100644 --- a/android/src/main/java/com/masteratul/RNAppstoreVersionCheckerModule.java +++ b/android/src/main/java/com/masteratul/RNAppstoreVersionCheckerModule.java @@ -28,8 +28,13 @@ public void appVersionExtractor( Callback errorCallback) { try { Document doc = Jsoup.connect(url).get(); - Elements versionElement = doc.select(extractor); - String versionText = versionElement.text(); + String versionText; + if(extractor.equalsIgnoreCase("")){ + versionText = doc.getElementsContainingOwnText("Current Version").parents().first().getAllElements().last().text(); + }else{ + versionText = doc.select(extractor).text(); + } + // https://stackoverflow.com/a/49924787/2881112 successCallback.invoke(versionText); } catch (Exception e) { errorCallback.invoke(e.getMessage()); diff --git a/src/versionChecker.android.js b/src/versionChecker.android.js index f3c806b..285660e 100644 --- a/src/versionChecker.android.js +++ b/src/versionChecker.android.js @@ -1,10 +1,10 @@ import {NativeModules} from 'react-native'; import {get} from './fetcher'; +const getAppstoreAppVersion = (id, options = { jquerySelector: "" }) => { -const getAppstoreAppVersion = (id, { jquerySelector = '[itemprop=\'softwareVersion\']' }) => { const url = `https://play.google.com/store/apps/details?id=${id}`; return new Promise((resolve, reject) => { - NativeModules.RNAppstoreVersionChecker.appVersionExtractor(url,jquerySelector,resolve, reject); + NativeModules.RNAppstoreVersionChecker.appVersionExtractor(url,options.jquerySelector,resolve, reject); }); };