From 8f398b827ed2717c2e46bee1df73822033f126cc Mon Sep 17 00:00:00 2001 From: Fabian Off Date: Wed, 5 Sep 2018 17:01:15 +0200 Subject: [PATCH 1/5] add installationSource to identify test versions and sideloaded apps --- .../main/java/com/apsl/versionnumber/RNVersionNumberModule.java | 2 ++ index.js | 2 ++ ios/RNVersionNumber.m | 1 + 3 files changed, 5 insertions(+) diff --git a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java index c7ab63e..390a66e 100644 --- a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java +++ b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java @@ -20,6 +20,7 @@ public class RNVersionNumberModule extends ReactContextBaseJavaModule { private static final String APP_VERSION = "appVersion"; private static final String APP_BUILD = "buildVersion"; private static final String APP_ID = "bundleIdentifier"; + private static final String APP_INSTALLATION_SOURCE = "installationSource"; public RNVersionNumberModule(ReactApplicationContext reactContext) { super(reactContext); @@ -39,6 +40,7 @@ public Map getConstants() { try { constants.put(APP_VERSION, packageManager.getPackageInfo(packageName, 0).versionName); constants.put(APP_BUILD, packageManager.getPackageInfo(packageName, 0).versionCode); + constants.put(APP_INSTALLATION_SOURCE, packageManager.getInstallerPackageName()); constants.put(APP_ID, packageName); } catch (NameNotFoundException e) { e.printStackTrace(); diff --git a/index.js b/index.js index 3dee4c0..44d485b 100644 --- a/index.js +++ b/index.js @@ -7,12 +7,14 @@ const { RNVersionNumber } = NativeModules; type VersionObject = { appVersion: ?string, buildVersion: ?string, + installationSource: ?string, bundleIdentifier: ?string }; const VersionNumber: VersionObject = { appVersion: RNVersionNumber && RNVersionNumber.appVersion, buildVersion: RNVersionNumber && RNVersionNumber.buildVersion, + installationSource: RNVersionNumber && RNVersionNumber.installationSource, bundleIdentifier: RNVersionNumber && RNVersionNumber.bundleIdentifier }; diff --git a/ios/RNVersionNumber.m b/ios/RNVersionNumber.m index d6aac84..a3c73a3 100644 --- a/ios/RNVersionNumber.m +++ b/ios/RNVersionNumber.m @@ -13,6 +13,7 @@ - (NSDictionary *)constantsToExport { return @{@"appVersion" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"buildVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey], + @"installationSource" : [[[NSBundle mainBundle] appStoreReceiptURL] path], @"bundleIdentifier" : [[NSBundle mainBundle] bundleIdentifier] }; From fbf12e1b49a6bc0801e0624dcd7c2276fdfcc018 Mon Sep 17 00:00:00 2001 From: Fabian Off Date: Wed, 5 Sep 2018 18:29:31 +0200 Subject: [PATCH 2/5] fix missing argument for PackageManager.getInstallerPackageName --- .../main/java/com/apsl/versionnumber/RNVersionNumberModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java index 390a66e..3d954a2 100644 --- a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java +++ b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java @@ -40,7 +40,7 @@ public Map getConstants() { try { constants.put(APP_VERSION, packageManager.getPackageInfo(packageName, 0).versionName); constants.put(APP_BUILD, packageManager.getPackageInfo(packageName, 0).versionCode); - constants.put(APP_INSTALLATION_SOURCE, packageManager.getInstallerPackageName()); + constants.put(APP_INSTALLATION_SOURCE, packageManager.getInstallerPackageName(packageName)); constants.put(APP_ID, packageName); } catch (NameNotFoundException e) { e.printStackTrace(); From 9e137d6b0112b1a16dfbc3d214f931f5fa0d91f3 Mon Sep 17 00:00:00 2001 From: Fabian Off Date: Wed, 31 Jul 2019 14:35:08 +0200 Subject: [PATCH 3/5] add installationSource to typescript module --- index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/index.d.ts b/index.d.ts index 1d6d347..abe88ba 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,4 +2,5 @@ declare module 'react-native-version-number' { export const appVersion: string export const buildVersion: string export const bundleIdentifier: string + export const installationSource: string } \ No newline at end of file From 697674d9793aff0bdae42c65773cbb476992a23c Mon Sep 17 00:00:00 2001 From: "Madd.is" Date: Wed, 31 Jul 2019 16:52:48 +0200 Subject: [PATCH 4/5] fix podspec --- react-native-version-number.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-native-version-number.podspec b/react-native-version-number.podspec index 67c862e..796cb14 100644 --- a/react-native-version-number.podspec +++ b/react-native-version-number.podspec @@ -10,8 +10,8 @@ Pod::Spec.new do |s| s.license = package_json["license"] s.author = { package_json["author"] => package_json["author"] } s.platform = :ios, "7.0" - s.source = { :git => "#{package_json["repository"]["url"]}.git", :tag => "v#{s.version}" } + s.source = { :git => "#{package_json["repository"]["url"]}" } s.source_files = 'ios/*.{h,m}' s.dependency 'React' -end \ No newline at end of file +end From c5ef49364fe8f5be4d5c0fed53e5184bab0a0b1f Mon Sep 17 00:00:00 2001 From: "Madd.is" Date: Thu, 21 Apr 2022 18:03:26 +0200 Subject: [PATCH 5/5] fix crash when running within MacOS x86 Rosetta 2 --- ios/RNVersionNumber.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ios/RNVersionNumber.m b/ios/RNVersionNumber.m index a3c73a3..07d75b5 100644 --- a/ios/RNVersionNumber.m +++ b/ios/RNVersionNumber.m @@ -11,9 +11,14 @@ - (dispatch_queue_t)methodQueue - (NSDictionary *)constantsToExport { + NSString* receipt = [[[NSBundle mainBundle] appStoreReceiptURL] path]; + #if TARGET_IPHONE_SIMULATOR + NSLog(@"Running on the Device, installationSource might not be able to be detected. Should only happen on Xcode versions running the app with Rosetta"); + receipt = receipt != nil ? receipt : @"file:///private/var/mobile/Containers/Data/CoreSimulator/Application/FAKE_M1_Rosetta_Fallback/StoreKit/sandboxReceipt"; + #endif return @{@"appVersion" : [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"buildVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey], - @"installationSource" : [[[NSBundle mainBundle] appStoreReceiptURL] path], + @"installationSource" : receipt, @"bundleIdentifier" : [[NSBundle mainBundle] bundleIdentifier] };