How could the font size be disabled is a Xamarin.iOS app/code? I had done this in Xamarin.Android app using the following code:
private void initFontScale()
{
Configuration configuration = Resources.Configuration;
configuration.FontScale = (float)1.45;
//0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big
DisplayMetrics metrics = new DisplayMetrics();
WindowManager.DefaultDisplay.GetMetrics(metrics);
metrics.ScaledDensity = configuration.FontScale * metrics.Density;
BaseContext.Resources.UpdateConfiguration(configuration, metrics);
}
What would be the equivalent of doing this in an iOS Xamarin app? Any help would be greatly appreciated.
Use this in your App code behind before you initialise your pages:
Xamarin.Forms.Application.Current.On<iOS>().SetEnableAccessibilityScalingForNamedFontSizes(false);
You'll need to include these:
using Xamarin.Forms.PlatformConfiguration;
using Xamarin.Forms.PlatformConfiguration.iOSSpecific;
Related
I have this code:
var myDocuments = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "..", "Shared");
_rootPath = Path.Combine(myDocuments, "VisitsRota.MacOS");
_stylesPath = Path.Combine(_rootPath, "Styles");
_vrrDataFile = Path.Combine(_rootPath, "VisitsRotaData.xml");
// Read in the required data
vrrData = DeserializeFromXml<VisitsRotaData>(_vrrDataFile);
// Build list of month names. Should this property also have a private counterpart?
ListMonths = DateTimeFormatInfo.CurrentInfo.MonthNames.TakeWhile(m => m != String.Empty).ToList();
// Select the current month in the list
ListMonthsSelectedItem = DateTime.Now.ToString("MMMM");
string[] stylesArray = Directory.GetFiles(_stylesPath, "ElderlyInfirm-Schedule-*.xsl")
.Select(file => Path.GetFileName(file)).ToArray<string>();
On the Mac it runs as expect. But on the iOS simulator (which I am new to using) it raises an exception:
System.IO.DirectoryNotFoundException: Could not find a part of the
path
'/Users/xxxxxxx/Library/Developer/CoreSimulator/Devices/B812608B-8131-4386-B189-C646684A8965/data/Containers/Data/Application/EF23B73D-8D38-4F41-995E-FCAE13AE3035/Shared/VisitsRota.MacOS/Styles'.
How should I be able to replicate testing on my iOS build? if I use literal paths instead of Path.Combine etc. I do not have a problem.
I was able to resolve this. My related question / answer about resources helped.
In the comments to this question I was asked:
How are these files being deployed with your app?
That was the key!
I added a constructor to the AppDelegate class:
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public AppDelegate()
{
InstallApplicationFiles();
}
The linked Q & A has more info. By getting the app to copy the default files from the resources the issue of paths with the iOS simulator is resolved.
I have xamarin.forms app. When user change the device font size in accessibility settings of android, My apps design gets scrampled. Which I am able to prevent.Now the problem I am facing is when user change the display size in the settings of android again my design gets distorted. How can I prevent this? Any help is appreciated.
I have xamarin.forms app. When user change the device font size in accessibility settings of android, My apps design gets scrampled. Which I am able to prevent.Now the problem I am facing is when user change the display size in the settings of android again my design gets distorted. How can I prevent this? Any help is appreciated.
You can try the following code in Mainactivity.cs:
private void initFontScale()
{
Configuration configuration = Resources.Configuration;
configuration.FontScale = (float)1;
//0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big
DisplayMetrics metrics = new DisplayMetrics();
WindowManager.DefaultDisplay.GetMetrics(metrics);
metrics.ScaledDensity = configuration.FontScale * metrics.Density;
//BaseContext.Resources.UpdateConfiguration(configuration, metrics);
BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
BaseContext.Resources.DisplayMetrics.SetTo(metrics);
}
protected override void OnCreate(Bundle savedInstanceState)
{
initFontScale();
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
...
LoadApplication(new App());
}
you can also try to override attachBaseContext method:
protected override void AttachBaseContext(Context #base)
{
Configuration overrideConfiguration = new Configuration();
overrideConfiguration = #base.Resources.Configuration;
overrideConfiguration.SetToDefaults();
var fontScale = overrideConfiguration.FontScale;
overrideConfiguration.FontScale = (float)1;
Context context = #base.CreateConfigurationContext(overrideConfiguration);
base.AttachBaseContext(context);
}
I want to share my solution for the same problem, hopefully it can be helpful for someone.
private void InitFontScale()
{
Configuration configuration = Resources.Configuration;
configuration.FontScale = (float) 1;
//0.85 small, 1 standard, 1.15 big,1.3 more bigger ,1.45 supper big
DisplayMetrics metrics = new DisplayMetrics();
WindowManager.DefaultDisplay.GetMetrics(metrics);
//I added the next lines to keep the density.
metrics.Density = configuration.FontScale * (DisplayMetrics.DensityDeviceStable / 160 f);
metrics.ScaledDensity = metrics.Density;
configuration.DensityDpi = (int) DisplayMetrics.DensityDeviceStable;
metrics.DensityDpi = (DisplayMetricsDensity) DisplayMetrics.DensityDeviceStable;
BaseContext.ApplicationContext.CreateConfigurationContext(configuration);
BaseContext.Resources.DisplayMetrics.SetTo(metrics);
}
I am reading this documentation/article from Microsoft on how to Distribute Mobile apps with app center. The problem is I really don't understand how to implement this. I have a app on app center (Android) I want to implement mandatory update so that I can eliminate the bugs of the previous version. I tried to distribute the app with mandatory update enabled and it is not working. How can I fix this?
https://learn.microsoft.com/en-us/appcenter/distribution/
Here is what I did I added this code on my App.xaml.cs (XAMARIN FORMS PROJECT):
protected override void OnStart ()
{
AppCenter.Start("android={Secret Code};", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Analytics.SetEnabledAsync(true);
Distribute.SetEnabledAsync(true);
Distribute.ReleaseAvailable = OnReleaseAvailable;
}
bool OnReleaseAvailable(ReleaseDetails releaseDetails)
{
string versionName = releaseDetails.ShortVersion;
string versionCodeOrBuildNumber = releaseDetails.Version;
string releaseNotes = releaseDetails.ReleaseNotes;
Uri releaseNotesUrl = releaseDetails.ReleaseNotesUrl;
var title = "Version " + versionName + " available!";
Task answer;
if (releaseDetails.MandatoryUpdate)
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install");
}
else
{
answer = Current.MainPage.DisplayAlert(title, releaseNotes, "Download and Install", "Ask Later");
}
answer.ContinueWith((task) =>
{
if (releaseDetails.MandatoryUpdate || (task as Task<bool>).Result)
{
Distribute.NotifyUpdateAction(UpdateAction.Update);
}
else
{
Distribute.NotifyUpdateAction(UpdateAction.Postpone);
}
});
return true;
}
And here is what I added on my MainActivity.cs(ANDROID PROJECT):
AppCenter.Start("{Secret Code}", typeof(Analytics), typeof(Crashes), typeof(Distribute));
Looking at this App Center documentation here for Xamarin Forms -
You can customize the default update dialog's appearance by implementing the ReleaseAvailable callback. You need to register the callback before calling AppCenter.Start
It looks like you need to swap your current ordering to get in-app updates working.
There could be a lot of different reasons as to why they are not working. As you can see in the Notes here and here,
Did your testers download the app from the default browser?
Are cookies enabled for the browser in their settings?
Another important point you'll read in the links, is that the feature is only available for listed distribution group users. It is not for all your members. You could use a simple version checker for your purpose instead or you could use a plugin.
I'm working on Unity 5.1.1f1 and using Unity cloud build for iOS with xcode 7 option. My problem is I can't disable App transport Security for my server url, disable bitcode and enable "requires full screen" option on xcode 7. So, game always errors when build.
Any solution is appreciated
Thanks for advice!
This is how I did it. It disables BitCode and enable UIRequiresFullScreen.
Tested with XCode 7.3 and Unity 5.4.1p2 version.
Please upgrade to latest version of Unity
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
public class Postprocessor : AssetPostprocessor
{
#if UNITY_IOS
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
{
if (buildTarget == BuildTarget.iOS)
{
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
PBXProject proj = new PBXProject();
proj.ReadFromString(File.ReadAllText(projPath));
string target = proj.TargetGuidByName("Unity-iPhone");
proj.SetBuildProperty(target, "ENABLE_BITCODE", "false");
File.WriteAllText(projPath, proj.WriteToString());
// Add url schema to plist file
string plistPath = path + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
// Get root
PlistElementDict rootDict = plist.root;
rootDict.SetBoolean("UIRequiresFullScreen",true);
plist.WriteToFile(plistPath);
}
}
#endif
}
I'm trying to support the new Windows Phone tile functionality in my existing Windows Phone OS 7.1 application, using the documentation from MSDN. However, I can't seem to create an IconicTile through reflection as it keeps giving me NullReferenceExceptions and AmbiguousMatchExceptions. Here is the code I am using:
public static void CreateIconicTile(Uri tileId, string title, int count, string wideContent1, string wideContent2, string wideContent3, Uri smallIconImage, Uri iconImage, Color backgroundColor)
{
// Get the new IconicTileData type.
Type iconicTileDataType = Type.GetType("Microsoft.Phone.Shell.IconicTileData, Microsoft.Phone");
// Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates.
Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
// Get the constructor for the new IconicTileData class and assign it to our variable to hold the Tile properties.
StandardTileData CreateTileData = new StandardTileData();
// Set the properties.
SetProperty(CreateTileData, "Count", count);
SetProperty(CreateTileData, "WideContent1", wideContent1);
SetProperty(CreateTileData, "WideContent2", wideContent2);
SetProperty(CreateTileData, "WideContent3", wideContent3);
SetProperty(CreateTileData, "SmallIconImage", smallIconImage);
SetProperty(CreateTileData, "IconImage", iconImage);
SetProperty(CreateTileData, "BackgroundColor", backgroundColor);
// Invoke the new version of ShellTile.Create.
shellTileType.GetMethod("Create").Invoke(null, new Object[] { tileId, CreateTileData });
}
I also tried creating the tile using the Windows Phone OS 7.1 way (ShellTile.Create(...)) and then calling the UpdateIconicTile method via reflection as described in the MSDN documentation. But that didn't work either.
Any help would be greatly appreciated. Thanks!
EDIT: Just to clarify, I am checking the platform version to ensure this code only runs on Windows Phone 8 devices and I have added the necessary code to my manifest.
RESOLVED: Thanks to the answer given by Martin Suchan below, I was able to solve this problem. The problem was with my call to Invoke(...) missing some properties. Here is the new line I am using to actually create the tile:
shellTileType.GetMethod("Create", new Type[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }).Invoke(null, new Object[] { tileId, CreateTileData, true });
Have you tried the library Mangopollo, that contains working wrapper for creation new tiles in WP7.1 apps when running on WP8?
http://mangopollo.codeplex.com/
You have to make sure that reflection is enabled across the code.
Iconic Tiles are only available for windows phone 8 therefore you can only put the code into a windows phone 7.1 project if you check the version
private static Version TargetedVersion = new Version(8, 0);
public static bool IsTargetedVersion {get{
return Environment.OSVersion.Version >= TargetedVersion;}}
Now see if the bool IsTargetedVersion is true. Basically,
if(IsTargetedVersion){
//iconic tile code
}
Thus only when a windows phone with compatible features (i.e. an wp8) runs your app then it will work.