Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -39,6 +40,7 @@ public Map<String, Object> 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();
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
6 changes: 6 additions & 0 deletions ios/RNVersionNumber.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]
};

Expand Down
4 changes: 2 additions & 2 deletions react-native-version-number.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
end