diff --git a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java index c7ab63e..3d954a2 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(packageName)); constants.put(APP_ID, packageName); } catch (NameNotFoundException e) { e.printStackTrace(); 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 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..07d75b5 100644 --- a/ios/RNVersionNumber.m +++ b/ios/RNVersionNumber.m @@ -11,8 +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" : receipt, @"bundleIdentifier" : [[NSBundle mainBundle] bundleIdentifier] }; 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