Date Time Picker

You can use native IOS  Date Time Picker  when you want your player to pick date, time or delay.

The following code snippet demonstrates how to show a date picker:

DateTimePicker.Show(DateTimePickerMode.Time, (dateTime) => {
//TODO callback realization
});

You also need to specify Date Time Picker mode as Show method parameter. Mode represented as IOSDateTimePickerMode enum.

The Date Time Picker will appear at the bottom of the screen.  And it will look similar to pictures below:

            

You can manually pre-set date without DateTimePicker UI. The following code snippet demonstrates how to do it:

public static void Show(DateTimePickerMode mode, DateTime dateTime, Action<DateTime> callback)

where the mode must be IOSDateTimePickerMode.Date.

 

To find out what date was selected by user, you can use 2 actions:

  • Action<DateTime> OnPickerDateChanged - will be fired each time user selects the new date in the picker.
  • Action<DateTime> OnPickerClosed; - fired when picker is closed.

 

The following snippet demonstrates how to subscribe to those actions and read a selected date.

//Subscribing to actions
DateTimePicker.OnPickerDateChanged += OnPickerDateChanged
DateTimePicker.OnPickerClosed      += OnPickerClosed;

//Showing the Date Time Picker
DateTimePicker.Show(DateTimePickerMode.DateAndTime, (dateTime) => {
//TODO callback realization
});

void OnDateChanged (System.DateTime time) {
	ISN_Logger.Log("OnDateChanged: " + time.ToString());
}

void OnPickerClosed (System.DateTime time) {
	ISN_Logger.Log("OnPickerClosed: " + time.ToString());
}

API Reference

IOSDateTimePicker

namespace SA.IOSNative.UIKit {
	public static class DateTimePicker  {
		
		public static event Action<DateTime> OnPickerClosed;
		public static event Action<DateTime> OnPickerDateChanged;

		#if (UNITY_IPHONE && !UNITY_EDITOR) || SA_DEBUG_MODE
		[DllImport ("__Internal")]
		private static extern void _ISN_ShowDP(int mode);

		[DllImport ("__Internal")]
		private static extern void _ISN_ShowDPWithTime(int mode, double seconds);
		#endif


		static DateTimePicker() {
			NativeReceiver.Instance.Init ();
		}

		//--------------------------------------
		// Public Methods
		//--------------------------------------

		/// <summary>
		/// Displays DateTimePickerUI with DateTimePicker Mode.
		///
		///<param name="mode">An object that contains the IOSDateTimePicker mode.</param>
		/// </summary>	
		public static void Show(DateTimePickerMode mode, Action<DateTime> callback);

		/// <summary>
		/// Displays DateTimePickerUI with DateTimePicker Mode and pre-set date.
		///
		///<param name="mode">An object that contains the IOSDateTimePicker mode</param>
		///<param name="name">An object DateTime that contains pre-set date</param>
		/// </summary>
		public static void Show(DateTimePickerMode mode, DateTime dateTime, Action<DateTime> callback);

		//--------------------------------------
		// Events
		//--------------------------------------

		internal static void DateChangedEvent(string time);
		internal static void PickerClosed(string time);
	}
}

IOSDateTimePickerMode

namespace SA.IOSNative.UIKit {
	
	public enum DateTimePickerMode  {
		
		Time = 1, // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)
		Date = 2, // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)
		DateAndTime = 3, // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
		CountdownTimer = 4 // Displays hour and minute (e.g. 1 | 53)
	}
}

Example Scenes

The full example of using can be found at the NativeIOSActionsExample example scene.