How to Set The Date and Time Programmatically in iOS

How to set the date and time programmatically in iOS

You can't set the date and/or time on iPhone/iPad programmatically. Those APIs are considered protected by Apple. In other words if you were to use those APIs and submit an app using them it would be rejected.

Edit:

To get documentation on this you can contact Apple Developer Technical Support using one of your free tech support incidents included with your developer program. LINK

programmatically setting DatePicker time to current time

setDate: method is used for setting specific date

[yourDatePicker setDate:[NSDate date]];

It will set picker date and time to current date and time.

How to get the value of General - Date & Time - Set Automatically programmatically in the iphone?

There is no way to get the value of that setting. Even if you could, it wouldn't mean anything at times because the user could be out of cell coverage meaning the time may not be accurate anyway.

How to create an iOS Time Picker programmatically?

This is what I ended up doing:

I found this popover solution -> https://github.com/werner77/WEPopover

That created the popover I wanted, then added this bit of code to the

- (void)viewDidAppear:(BOOL)animated method

// place inside a temporary view controller and add to popover

UIViewController *viewCon = [[UIViewController alloc] init];

// PopOverViewController *viewCon = [[PopOverViewController alloc] init];

UIDatePicker *timePick;
timePick = [[UIDatePicker alloc]initWithFrame:CGRectMake(5, 0, 0, 0)];
timePick.datePickerMode =UIDatePickerModeTime;

[viewCon.view addSubview:timePick];

// viewCon.view = label;

viewCon.contentSizeForViewInPopover = timePick.bounds.size ; // Set the content size

popover = [[WEPopoverController alloc] initWithContentViewController:viewCon];

[popover presentPopoverFromRect:CGRectMake(0, 10, 0, 120)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown
animated:YES];

The only problem now is resizing the picker to the width that I want....other than that, it works!

The solutions that were presented will only work for an iPad not an iPhone....

Thanks everyone.



Related Topics



Leave a reply



Submit