Closed Dontag closed 4 years ago
Hi, my time is very limited at the moment but I'd be super happy to accept a PR.
That being said, where did you get blocked?
Did you install the npm module and try it out?
Did you run pod install
on your iOS dir after the npm installation?
Also what react-native version are you on? The whole installation process should be straight forward and pretty much automatic if you're on RN > 61
Hi, I'm using Android Platform SDK v29, React-Native - v0.61.5.
I tried it out but it is not showing any result or throwing any error.
To implement it just as you have shown in the example(GIF), can you share one reference code?
Is this code enough to test?
inAppUpdates.checkNeedsUpdate({
curVersion: '4.8.8',
toSemverConverter: (ver => {
// i.e if 400401 is the Android version, and we want to convert it to 4.4.1
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 = result.other.updatePriority >= HIGH_PRIORITY_UPDATE
? SpInAppUpdates.UPDATE_TYPE.IMMEDIATE
: SpInAppUpdates.UPDATE_TYPE.FLEXIBLE;
inAppUpdates.startUpdate({
updateType, // android only, on iOS the user will be promped to go to your app store page
})
} })
The following is the code we run in our production app :
module.exports = { // cached singleton instance
startNativeUpdate() {
return inAppUpdates.startUpdate({
updateType: SpInAppUpdates.UPDATE_TYPE.FLEXIBLE
});
},
nativeUpdateExists(curAppVersion) {
if (!updateInfoRan && curAppVersion) {
updateInfoRan = true;
inAppUpdates.checkNeedsUpdate({
curVersion: curAppVersion,
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 => ({
isNeeded: !!result.shouldUpdate,
latestVersion: result.storeVersion,
currentVersion: curAppVersion,
}))
.catch(err => {
logError(`nativeUpdateExists err: ${err}`);
});
}
return Promise.resolve({ isNeeded: false, currentVersion: curAppVersion });
},
};
and then at some point we invoke:
startNativeUpdate().then(result=> {
console.log(result)
}).catch(errr => {
console.log(errr)
});
👍
how to check if the update is downloading using addStatusUpdateListener?
or how to add listener and check the status ?
the document is difficult to understand
there should be an example code to understand the flow
addStatusUpdateListener:
inAppUpdates.addStatusUpdateListener(status => {
const {
status,
bytesDownloaded,
totalBytesToDownload,
} = status;
// do something
})
I'm getting array undefined error (this.statusUpdateListeners undefined)
//when trying
inAppUpdates.addStatusUpdateListener(status => { this.updateState(status); })
updateState => (status) = { //checking the status if (status.status === SpInAppUpdates.UPDATE_STATUS.UPDATE_DOWNLOADING) { // setting state } // else }
@Dontag What is the statusUpdateListeners
variable?
statusUpdateListeners is an array where the callback is getting stored
addStatusUpdateListener(callback) { if (!_.contains(this.statusUpdateListeners, callback)) { this.statusUpdateListeners.push(callback); } if (this.statusUpdateListeners.length > 0) { SpInAppUpdates.setStatusUpdateSubscription(true); } }
Apologies, I was under the impression statusUpdateListeners
was part of your implementation, obviously you're talking about this line of code: https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/d728d46860d7b63281676ed1d2c10c00d11d1212/lib/index.android.js#L64
It's possible that the context of the function could be wrong.
We probably need to use arrow functions. I can take a look tomorrow, but feel free to experiment with arrow functions and see if that's the problem. I'll post back.
Hey, @SudoPlz It will help us a lot if you give some example that how will I know Is update download completed or not? How could I detect that app downloading is completed so I can able to install it? awaiting for your response.
On this PR --> https://github.com/SudoPlz/sp-react-native-in-app-updates/pull/7 I'm attempting to add some examples to our project as well as rewrite this module with typescript:
Any help would be greatly appreciated since I'm still learning my ways around typescript.
pls can you add a example code.