I am using custom navbar for my project and I am using codes for ios 7 top margin as below;
var _IsIos7Plus = false;
if (Titanium.Platform.name == 'iPhone OS') {
var _Version = Titanium.Platform.version.split(".");
var _Major = parseInt(_Version[0], 10);
if (_Major >= 7) {
_IsIos7Plus = true;
}
}
Alloy.Globals.Ios7TopMargin = _IsIos7Plus == true ? 20 : 0;
But iPhone X simulator shows 20 blank. Is there any way to detect iPhone X?
If you upgrade your project firstly you should check
Default-Portrait-2436h#3x.png
Default-Landscape-2436h#3x.png
splash screens are exists
Than you can detect iPhoneX code as below;
var IsIphoneX = (Ti.Platform.displayCaps.platformWidth === 375 && Ti.Platform.displayCaps.platformHeight === 812 && Ti.Platform.displayCaps.logicalDensityFactor === 3);
Related
I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.
protected void UpdateBackground(UITextField control)
{
if (control == null) return;
control.Layer.CornerRadius = ElementV2.CornerRadius;
control.Layer.BorderWidth = ElementV2.BorderThickness;
control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();
var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
downArrowLabel.Text = "\uf0d7";
downArrowLabel.TextColor = UIColor.Black;
downArrowLabel.TextAlignment = UITextAlignment.Center;
downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
control.RightView = downArrowLabel;
control.RightViewMode = UITextFieldViewMode.Always;
control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}
I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this
downArrowLabel.Text = "\uf0d7 ";
Im using Xamarin Forms Maps, and I want to have the same feature on iOS as I have on Android devices - show all pins on the screen (appropriate position and zoom)
What Im looking is "Bounds" property, but that I only found on XF.GoogleMaps which nuget I dont use.
for Android in my custom renderer I pout LatLngBounds class and made a builder, thats works just fine, but on iOS I didnt find a solution.
Thanks
UPDATE #1:
Is this a right method in iOS renderer to put ShowAnnotations? And how to re-pack it to MkAnnotation from Pin model?
protected override void OnElementChanged(ElementChangedEventArgs<View> e)
{
base.OnElementChanged(e);
if (e.OldElement != null)
{
var nativeMap = Control as MKMapView;
nativeMap.GetViewForAnnotation = null;
nativeMap.ZoomEnabled = true;
nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView;
}
if (e.NewElement != null)
{
var formsMap = (CustomMap)e.NewElement;
var nativeMap = Control as MKMapView;
customPins = formsMap.CustomPins;
//MKAnnotation an = formsMap.CustomPins;
var numberOfPins = formsMap.CustomPins.Count;
MKAnnotation[] anotationArray = new MKAnnotation[numberOfPins];
for (int i = 0; i < numberOfPins; i++)
{
anotationArray[0].Coordinate = customPins.ElementAt(0).Position...
}
foreach (var pin in formsMap.CustomPins)
{
}
nativeMap.ZoomEnabled = true;
nativeMap.GetViewForAnnotation = GetViewForAnnotation;
nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped;
nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView;
nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView;
}
}
You are looking for the ShowAnnotations on your MKMapView.
You pass in the array of pins (annotations) that you wish the map to center and zoom to to able all those pins to the shows at the same time:
yourMapView.ShowAnnotations (new [] { pin }, false);
Apple Docs: showAnnotations:animated:
Xamarin Docs: ShowAnnotations
I want to access the device mac in xamarin ios but it always return 02:00:00:00:00:00.
if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
var address = netInterface.GetPhysicalAddress();
return BitConverter.ToString(address.GetAddressBytes());
}
}
return "000000000000";
I tried using nativescript like this but it doesnt work:
battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery || navigator.msBattery;
console.log("battery level: ", Math.floor(this.battery.level * 100) + "%");
you have to write respective native codes for getting Battery info.
for android you can register broadcastreciever for ACTION_BATTERY_CHANGED. and for ios you can use UIDevice.currentDevice.batteryLevel
example:
import { android as androidApp, ios as iosApp } from "application";
import { ios as iosUtils } from "utils/utils";
if (iosApp){
iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryMonitoringEnabled = true;
let battery = +(iosUtils.getter(UIDevice, UIDevice.currentDevice).batteryLevel * 100);
}else{
androidApp.registerBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED,(context: android.content.Context, intent: android.content.Intent) =>{
let level = intent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1);
let scale = intent.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1);
let percent = (level / scale) * 100.0;
});
}
I'm using the media manager nuget plugin and it's great, but for the life of me, I can't get the lock screen or car bluetooth to show the notifications. I'm using the following to display the notifications (set within OnAppearing)
ViewModel.PropertyChanged += (sender, e) =>
{
switch (e.PropertyName)
{
case "RadioSchedule":
if (listData != null)
{
listData.ItemsSource = null;
var first = ViewModel.RadioSchedule[0];
Device.BeginInvokeOnMainThread(() =>
{
listData.ItemsSource = ViewModel.RadioSchedule;
MediaFile.Metadata.Artist = MediaFile.Metadata.DisplaySubtitle = MediaFile.Metadata.AlbumArtist = first.Artist;
MediaFile.Metadata.Title = MediaFile.Metadata.DisplayTitle = first.Track;
MediaFile.Metadata.DisplayIcon = new Image { Source = "icon".CorrectedImageSource() };
MediaFile.Metadata.BluetoothFolderType = "1";
MediaFile.Type = MediaFileType.Audio;
MediaFile.Url = Constants.RadioStream;
MediaFile.Availability = ResourceAvailability.Remote;
MediaFile.MetadataExtracted = true;
MediaFile.Metadata.Date = DateTime.Now;
MediaFile.Metadata.Duration = 300;
MediaFile.Metadata.Genre = "Rock";
MediaFile.Metadata.TrackNumber = MediaFile.Metadata.NumTracks = 1;
MediaFile.Metadata.DisplayDescription = "Radio Station";
if (!ViewModel.NotificationStarted)
{
if (CrossMediaManager.Current.MediaNotificationManager != null)
CrossMediaManager.Current.MediaNotificationManager.StartNotification(MediaFile);
ViewModel.NotificationStarted = true;
}
CrossMediaManager.Current.MediaNotificationManager?.UpdateNotifications(MediaFile, MediaPlayerStatus.Playing);
});
}
break;
The code itself is being hit (I can set break points and they are hit). I've tried it on and off the UI thread as well.
The playlist comes from a webapi which works fine. The notifier gives unknown/unknown on the device media player (both iOS and Android) and nothing in-car. For Android, the permissions the readme file says to use have also been set.
Is there some sort of magic I have to do to get this to work? This is a Xam.Forms package rather than something native.
The MediaPlayer is started further in the class using the following code
CrossMediaManager.Current.Play(Constants.RadioStream, MediaFileType.Audio, ResourceAvailability.Remote);
Where Constants.RadioStream is the URL of the radio stream.