DatePicker not returning selected date iOS - ios

I am trying to get the selected date from a DatePicker and all I get is the current system date. Any ideas why?
I am doing it through the simulator as I do not have a device. Here is the code I use to get the date.
[self scheduleLocalNotification:timerPicker.date];
I have also used this to see if it works:
NSDate *d = [timerPicker date];
[self scheduleLocalNotification:d];

After several reboots of XCode and no code changes it magically started working.

Related

XCUITest, UIDatePicker, adjustToPickerWheelValue

I'm writing an XCUITest. I have a view with a UIDatePicker on it (NOT a regular picker).
I'm trying to set the date using adjustToPickerWheelValue.
This crashes with the following error:
caught "NSInvalidArgumentException", "-[XCUIElement(XCUIElementTypePickerWheel) adjustToPickerWheelValue:]_block_invoke can only be called with elements of type XCUIElementTypePickerWheel, not valid for DatePicker."
This implies of course that this method is not available for the UIDatePicker.
I've gone through the apple site and it states pretty clearly that it IS supported.
I can't find any examples of this used for a date picker.
It's possible of course that I'm just not setting it right (I'm not sure how one would pass a string date, for example).
This is the code I'm trying:
XCUIElement *DOB;
XCUIElementQuery *DOBList = app.datePickers;
DOB = [DOBList elementBoundByIndex:0];
NSLog(#"DOB = %#\n", [DOB description]);
[DOB adjustToPickerWheelValue:#"SOME DATE GOES HERE?"];
BTW - description is of a DatePicker.
Printing [DOB value] just returns an empty string.
Any ideas?
For using UIDatePickers, I do like that:
XCUIApplication().datePickers.firstMatch.pickerWheels["CurrentValue"].adjust(toPickerWheelValue: "NewValue")
You have to do that for each picker of the UIDatePicker.

How to get Lauch time of an ios application

I'm new to ios mobile testing. I need to get the launch time of an ios application. How would i do that using java or is there any other way to do it. Any advise on this would be helpful. Thanks in advance.
I don't think this is achievable in java since the iOS development is in Obj-C/Swift. However I'll answer your question.
You can get the launchDate DateTime.Now that start at the AppDelegate application:willFinishLaunchingWithOption and get the finishLoadDate DateTime.Nowon the ViewDidload method of the first View Controller that shows. And then compare these both dates to track the time difference.
This way you can track the time from the app was clicked, till the app was launched.
Hope that helps!
A lot of things happens before the system executes willFinishLaunchingWithOption.
So all you need to do in order to understand it, it's to set the environment variable DYLD_PRINT_STATISTICS.
Just click on edit scheme then select Run and set DYLD_PRINT_STATISTICS as and environment variable under arguments tab.
After that you will be able to see launching time in your debug console.
Haven't tested this, but it should help you get your solution:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSDate *fetchStart = [NSDate date];
NSDate *fetchEnd = [NSDate date];
NSTimeInterval timeElapsed = [fetchEnd timeIntervalSinceDate:fetchStart];
NSLog(#"Duration: %f seconds", timeElapsed);
return YES;
}
Hope this helps!

How to get UTC universal time from CLLocation locations?

It looks like the timestamp property of CLLocation takes the device's current date and time... I have this code snippet:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations lastObject];
NSDate *eventDate = newLocation.timestamp;
long long locTimestamp = [date timeIntervalSince1970] * 1000;
NSLog(#"Loc timestamp: %lld:", locTimestamp);
}
At the moment I'm writing this, if I print the description of eventDate in the Xcode's debug area console, I get:
Printing description of eventDate:
2015-08-26 15:14:09 +0000
And if I change the date in the device's settings, I get that wrong date in evenDate:
Printing description of eventDate:
2015-07-25 15:16:33 +0000
Maybe I'm misunderstanding the NSDate that is returned in the timestamp property... it really takes the date and time you have set in the device, or it is just given the format of those device's settings?
The point is, I need to get UTC times of locations to report them to a server and make some comparisons between different devices, and if user changes the date and time settings of his device and my app sends wrong or "fake" timestamps, my app couldn't perform well...
It seems that it is possible in Android apps to get the NMEA data from GPS and then get the universal time of positions, but I canĀ“t find that in iOS. Is it possible to get it in iOS?
I need help with this issue, thanks in advance
You can convert the timestamps into any calendar or timezone you want via the NSCalendar and NSDateFormatter and NSLocaleclasses. Docs here

Content modification date of an file in Cocoa

How can I find out when a file was last time modified in Cocoa?
I tried using NSFileModificationDate attribute of an NSFile but the modification date gets update when you read a file. I just want to know when it was last time changed like in the Mac OS X Finder.
You can try next code:
NSDate *fileModificationDate = nil;
[fileUrl getResourceValue:&fileModificationDate forKey:NSURLContentModificationDateKey error:nil];
NSLog(#"modification date %#", fileModificationDate)
You can see the resource keys in NSURL.h - NSURLContentModificationDateKey and other.
Hope it will help.

Time picker shows wrong time iphone sdk

I have time picker in my app. I'm showing timePicker.date and the time is wrong.
NSLog is
NSLog (#"date : %#",[timePicker.date description]);
log is like date: 2012-02-07 17:00:01 +0000
i think that problem is in timezone
in ViewDidLoad i have this code
timePicker.locale = [NSLocale currentLocale];
timePicker.timeZone = [NSTimeZone localTimeZone];
but it isn't working...
Can somebody help me to solve my problem. Thanks
It is likely that the time picker is correctly applying time zone, but you're logging it using GMT rather than local time so that it just looks wrong. If you want to display the time returned from your time picker using local time, use NSDate's descriptionWithCalendarFormat:timeZone:locale: method, or use the NSDateFormatter class to get complete control over how your date is displayed.

Resources