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

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

Crash Upon Starting download #97

Open Jad-Jbara opened 2 years ago

Jad-Jbara commented 2 years ago

Usage

import SpInAppUpdates, {
  AndroidInstallStatus,
  IAUUpdateKind,
  StartUpdateOptions,
} from 'sp-react-native-in-app-updates'

...
      InAppUpdates.addStatusUpdateListener((event) => {
        if (event.status === AndroidInstallStatus.DOWNLOADED) {
          InAppUpdates.installUpdate()
          InAppUpdates.removeStatusUpdateListener((status) => console.log(status))
        }
      })

Error from Playstore: com.facebook.react.common.JavascriptException: TypeError: Cannot read property 'DOWNLOADED' of undefined, js engine: hermes, stack: anonymous@1:852125 value@1:856681 anonymous@1:853884 value@1:93197 value@1:102582 anonymous@1:101065 value@1:102028 value@1:101023 at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java at java.lang.reflect.Method.invoke (Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:151) at com.facebook.react.bridge.queue.NativeRunnable.run (Native Method) at android.os.Handler.handleCallback (Handler.java:739) at android.os.Handler.dispatchMessage (Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27) at android.os.Looper.loop (Looper.java:148) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:226) at java.lang.Thread.run (Thread.java:818)

dibyopra commented 2 years ago

same issue here

Jad-Jbara commented 2 years ago

same issue here

@dibyopra I'm using the codes manually instead of importing them from AndroidInstallStatus as a workaround for now

dibyopra commented 2 years ago

same issue here

@dibyopra I'm using the codes manually instead of importing them from AndroidInstallStatus as a workaround for now

event.status === 11 // for downloaded status like that ?

Jad-Jbara commented 2 years ago

@dibyopra Yes exactly, should do the trick, haven't tested it yet though

dibyopra commented 2 years ago

Yes exactly, should do the trick, haven't tested it yet though

I have tried it, its working

gtjamesa commented 1 year ago

AndroidInstallStatus is exported from the library as IAUInstallStatus. So you can use IAUInstallStatus.DOWNLOADED instead.

console.log(AndroidInstallStatus?.DOWNLOADED, IAUInstallStatus.DOWNLOADED);

image

robbeman commented 1 year ago

I was running into the same issue, I suppose it's because they are passed through by index.d.ts, but not by index.js?

https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/154057630d77f437d6edbd74fcc2009c83981ab6/src/index.d.ts#L9-L16

https://github.com/SudoPlz/sp-react-native-in-app-updates/blob/154057630d77f437d6edbd74fcc2009c83981ab6/src/index.js#L1-L6

My suggestion would be to remove export * from './types'; from index.d.ts (may seem like a breaking change, but in fact it's not because the stuff exported by this is not available in compiled code, I think). Or update index.js to be typescript and remove the .d.ts file altogether so they can not diverge anymore.