sp-react-native-in-app-updates icon indicating copy to clipboard operation
sp-react-native-in-app-updates copied to clipboard

install update not work

Open muammadibal opened this issue 1 year ago • 5 comments

I found an issue, i've been tested with app internal sharing. Installing update only work with updateType IMMEDIATE and not work if FLEXIBLE

muammadibal avatar Mar 29 '23 06:03 muammadibal

@muammadibal Hi! Could you provide your code to see how you handle the process ?

Lepidopterolog avatar Mar 29 '23 12:03 Lepidopterolog

I found an issue, i've been tested with app internal sharing. Installing update only work with updateType IMMEDIATE and not work if FLEXIBLE

Hey @muammadibal can you please provide more information.

I'm working on it right now, and it works perfectly with both.

you can try this one:

import SpInAppUpdates, {
    IAUUpdateKind,
} from "sp-react-native-in-app-updates";

let updateType = IAUUpdateKind.IMMEDIATE or  IAUUpdateKind.FLEXIBLE
inAppUpdates.startUpdate({
                    updateType,
                });

I hope it will work for you.

ShravanMeena avatar Mar 31 '23 09:03 ShravanMeena

I guess you simply forgot to call an install, i.e. in the IMMEDIATE mode it is automatic but in FLEXIBLE you should do it yourself.

Lepidopterolog avatar Mar 31 '23 09:03 Lepidopterolog

yup, first i didn't put install

but base on resource i found at issue section. they suggest to use listener then do installUpdate, but unfortunately my update doesn't work at all even download the update

IAUUpdateKind.FLEXIBLE

inAppUpdates.addStatusUpdateListener((downloadStatus) => {
   if (downloadStatus.status === IAUInstallStatus.DOWNLOADED) { 
      inAppUpdates.installUpdate();
   }
});
inAppUpdates.startUpdate(updateOptions);

then i found

inAppUpdates.startUpdate(updateOptions).then(() => inAppUpdates.installUpdate());

but still not work

muammadibal avatar Apr 01 '23 03:04 muammadibal

@muammadibal

Definitely the first option is right! The 2nd option should not work. I don't know where you got it.

You need to find the specific moment in the code when the update stop down, and from this you may understand what exactly is going wrong. Also, make sure that you test the updates exactly according to the instructions. You can provide the entire code to review here just in case.

I will leave the basic version of the code (only for Android) and some important points like a reminding the google store returns exactly the code version (build number) not the semantic version (x.y.z) unlike ios. So, you must pass your version for comparison to the checkNeedsUpdate method, which you will receive as getBuildNumber from react-native-device-info. Or if you need to work exactly with the semantic version, store it somewhere on the backend yourself (but I wouldn't recommend it). Otherwise the library will take getVersion by default and this is not correct for Android.

const listener = ({ status }) => {
	if (status === IAUInstallStatus.DOWNLOADED) inAppUpdates.installUpdate()
}

inAppUpdates
	.checkNeedsUpdate({ curVersion })
	.then(({ shouldUpdate }) =>
		if (shouldUpdate) {
			// only for Android
			if (isAndroid) inAppUpdates.addStatusUpdateListener(listener)
			inAppUpdates.startUpdate(...)

Lepidopterolog avatar Apr 01 '23 14:04 Lepidopterolog