I have added Settings.bundle
to my app to add version and build numbers in app settings, and it is added properly. The issue I have is, that it is always getting default value only and after that it is not updating it based on the value from actual app version and build number (even after running the app).
Root.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>StringsTable</key>
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>DefaultValue</key>
<string>1.0</string>
<key>Key</key>
<string>current_version_number</string>
<key>Title</key>
<string>Version</string>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
</dict>
</array>
</dict>
</plist>
I have created this custom class to update version and build number:
public static class SettingsBundleHelper
{
static string AppVersionKey = "current_version_number";
public static void SetVersionAndBuildNumber()
{
string version = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString();
string build = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleVersion").ToString();
NSUserDefaults.StandardUserDefaults.SetString(AppVersionKey, $"{version}({build})");
NSUserDefaults.StandardUserDefaults.Synchronize();
}
}
App Delegate:
public override void OnActivated(UIApplication application)
{
SettingsBundleHelper.SetVersionAndBuildNumber();
}
I followed this tutorial to implement this feature.
After this, version number in app settings is always 1.0
Another Question:
How to implement auto increment build number in Xamarin.iOS
app? Because I don't want to update info.plist
build number each time I create new ipa
.