SudoPlz / sp-react-native-in-app-updates

An in-app updater for the native version of your react-native app.
MIT License
491 stars 66 forks source link

Not able to open In app update in OnePlus devices. Any Solution for this? #9

Closed Ashu81045 closed 4 years ago

Ashu81045 commented 4 years ago

Implementing this library in js file with functional components What i am doing inside my code is

import SpInAppUpdates, { UPDATE_TYPE } from 'sp-react-native-in-app-updates'; const inAppUpdates = new SpInAppUpdates();

const checkForUpdates = () => { let currentAppVersion = DeviceInfo.getVersion(); //getting installed app version through this inAppUpdates .checkNeedsUpdate({ curVersion: currentAppVersion, toSemverConverter: ver => { const androidVersionNo = parseInt(ver, 10); const majorVer = Math.trunc(androidVersionNo / 10000); const minorVerStarter = androidVersionNo - majorVer 10000; const minorVer = Math.trunc(minorVerStarter / 100); const patchVersion = Math.trunc(minorVerStarter - minorVer 100); return ${majorVer}.${minorVer}.${patchVersion}; }, }) .then(result => { if (result.shouldUpdate) { const updateType = UPDATE_TYPE.IMMEDIATE ; //doing this for force update so set it immediate inAppUpdates.startUpdate({ updateType, }); } }) .catch(err => { console.log('error occurred while in app update', err); }); }; //JSX part <CustomButton style={styles.btnUpdate} handler={() => checkForUpdates()} title="InAppUpdate" />

Current Behaviour :
MI device : In App update popup apears in app only.( Working as expected) OnePlus 5 device : Nothing happened after clicking the same button.

Debug the code for onePlus device it is giving me success in promise.But result.shouldupdate is giving false and store version is undefined. Any specific reason for this?

With mi device it is giving me result.shouldupdate is giving true and store version is XXX.XX.49 which is correct.

Let me know if any other configuration or anything required from my side so that it can be workable in oneplus device

If for anyone this library is working for all devices . Please share code .

SudoPlz commented 4 years ago

Interesting, I'm not aware of that at all, but I'm assuming the issue is coming from Google's java code, can you please add a breakpoint here: https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/android/src/main/java/com/sudoplz/rninappupdates/SpInAppUpdatesModule.java#L102 and check what version the appUpdateInfo contains?

Ashu81045 commented 4 years ago

Thanks for the reply .I will update here with appUpdateInfo findings after debugging code.

Ashu81045 commented 4 years ago

I have debug Java code https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/master/android/src/main/java/com/sudoplz/rninappupdates/SpInAppUpdatesModule.java#L102 and checked the result of appUpdateInfo. ===============For OnePlus device ========================= { packageName=app.xxxx.in, availableVersionCode=XXXXX38, updateAvailability=1, installStatus=0, clientVersionStalenessDays=null, updatePriority=0, bytesDownloaded=0, totalBytesToDownload=0, additionalSpaceRequired=0, assetPackStorageSize=0, immediateUpdateIntent=null, flexibleUpdateIntent=null, immediateDestructiveUpdateIntent=null, flexibleDestructiveUpdateIntent=null } And for MI device availableVersionCode=XXXXX49. //which is correct

Also, i checked into inAppUpdateAndroid.ts file -> Inside checkNeedsUpdate method i got inAppUpdateInfo object as below { totalBytes: 0 packageName: "app.allendigital.in" versionCode: XXXXX38 updatePriority: 0 isFlexibleUpdateAllowed: false isImmediateUpdateAllowed: false updateAvailability: 1 }

So , i think problem is we are receiving lower no version code in case of OnePlus device from google. Is there any way to get proper version code form there ?

SudoPlz commented 4 years ago

So this is google territory, I can't really help much with that. All this module does is wrapping the in-app-update sdk of Google, if that returns the wrong version it's outside the scope of this library, and I'm not really familiar with how that works. Sorry I wish I could help more :/

rewhex commented 3 years ago

@SudoPlz Your library as i see, is comparing versionCode from store with versionName from device info, this will not work unless curVersion is specified as versionCode manually.

SudoPlz commented 3 years ago

You're absolutely right @rewhex . This seems confusing, and we didn't really realise it because we're using a customVersionComparator on our end (which converts version names to version codes).

We'll have to definitely resolve that on the default comparator or just better document the usage so that folks pass their own customVersionComparator.

Feel free to use that for now, and if you feel like opening a PR to resolve that I'd be more than happy to review.

rewhex commented 3 years ago

@SudoPlz versionCode can be anything, you cannot convert versionName to versionCode, you must compare only version code, as this is the only thing that can differ: two apps with same versionName can have a different versionCode

rewhex commented 3 years ago

@SudoPlz just noticed that you said, you use it in your project, maybe then you just need to allow us to choose which one to check, versionCode or versionName.

SudoPlz commented 3 years ago

I hear you, it sounds like we'll want to support both variables and use whichever is passed.