Last active
January 5, 2021 14:31
-
-
Save jamesmontemagno/f206315dbbee74a277a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Snippet Name: iOS Utils | |
Platform: Xamarin.iOS | |
Function: Check if running iOS 8, is phone, is tall, and envoke on UI Thread | |
Snippet: | |
public static class Utils | |
{ | |
public static NSObject Invoker; | |
/// <summary> | |
/// Ensures the invoked on main thread. | |
/// </summary> | |
/// <param name="action">Action to run on main thread.</param> | |
public static void EnsureInvokedOnMainThread(Action action) | |
{ | |
if (NSThread.Current.IsMainThread) | |
{ | |
action(); | |
return; | |
} | |
if (Invoker == null) | |
Invoker = new NSObject(); | |
Invoker.BeginInvokeOnMainThread(() => action()); | |
} | |
public static bool IsiOS7 | |
{ | |
get | |
{ | |
return UIDevice.CurrentDevice.CheckSystemVersion(7, 0); | |
} | |
} | |
public static bool IsiOS8 | |
{ | |
get | |
{ | |
return UIDevice.CurrentDevice.CheckSystemVersion(8, 0); | |
} | |
} | |
public static bool IsPhone | |
{ | |
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; } | |
} | |
//Check if taller than iPhone 4 | |
public static bool IsTallPhone | |
{ | |
get | |
{ | |
return IsPhone && (UIScreen.MainScreen.Bounds.Height * UIScreen.MainScreen.Scale >= 1136); | |
} | |
} | |
} | |
Example Use: | |
//Pop up items | |
Utils.EnsureInvokedOnMainThread (() => { | |
var alertView = new UIAlertView ("Title", "Message", null, "OK"); | |
alertView.Show (); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment