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

Allow Bypass of Update Alert on IOS #182

Open OluwaferanmiLove opened 4 months ago

OluwaferanmiLove commented 4 months ago

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch sp-react-native-in-app-updates@1.4.0 for the project I'm working on.

I am trying to use the package with my custom screen, but the custom Alert screen was the default

Here is the diff that solved my problem:

diff --git a/node_modules/sp-react-native-in-app-updates/src/InAppUpdates.ios.ts b/node_modules/sp-react-native-in-app-updates/src/InAppUpdates.ios.ts
index 33881ba..46ceaeb 100644
--- a/node_modules/sp-react-native-in-app-updates/src/InAppUpdates.ios.ts
+++ b/node_modules/sp-react-native-in-app-updates/src/InAppUpdates.ios.ts
@@ -94,6 +94,16 @@ export default class InAppUpdates extends InAppUpdatesBase {
   }

   startUpdate(updateOptions: IosStartUpdateOptions): Promise<void> {
+    if (updateOptions?.bypassAlert) {
+      return Promise.resolve(
+        Siren.performCheck().then(({ updateIsAvailable, trackId }) => {
+          if (updateIsAvailable) {
+            Siren.attemptUpgrade(trackId)
+          }
+        })
+      )
+    }
+
     return Promise.resolve(
       Siren.promptUser(
         updateOptions,
diff --git a/node_modules/sp-react-native-in-app-updates/src/types.ts b/node_modules/sp-react-native-in-app-updates/src/types.ts
index bfb97fc..ec8c360 100644
--- a/node_modules/sp-react-native-in-app-updates/src/types.ts
+++ b/node_modules/sp-react-native-in-app-updates/src/types.ts
@@ -170,6 +170,7 @@ type IosStartUpdateOption = {
   updateType?: never;
   bundleId?: string;
   country?: string;
+  bypassAlert?: boolean;
 };

 type IosStartUpdateOptionWithLocalVersion = IosStartUpdateOption & {

This issue body was partially generated by patch-package.

SudoPlz commented 4 months ago

Hey there, thanks for addressing that. Would you mind creating a PR for it? We should support this use-case. Also can you name the variable something like skipUserPrompt and add it on ReadMe too? (Also I wonder if we need to support that on android)