NSTimeZone initialisation results in "unable to read data" - ios

I'm trying to initialise an NSTimeZone object like this:
var timezone = NSTimeZone.init(name: "Europe/Moscow")
instead of nil or a legit locale value - I get "unable to read data" in xCode's debugging tool
I got the timezone string ("Europe/Moscow") via NSTimeZone.knownTimeZoneNames()
I'm using xCode 7
What am I doing wrong?

Haven't used that class before, but I'm guessing it should be let timezone = NSTimeZone(name : "")? Never seen a class initialized in that way.

Its working fine for me , use let instead of var.Check below
For reference
Swift NSDate UTC time and local time

As pointed out in the comments - the variables view was just wrong - a print() resulted in the correct output.
Running an iPhone 6 Simulator instead of an iPhone 5 simulator gives the expected results.

Related

iOS UITest error when try to select picker element

I'm trying to select an element of picker, the picker has Accessibility = picker_station, why can I do ? is something wrong ? or I need to use other code.
let app = XCUIApplication()
app.pickers["picker_station"].pickerWheels.element.adjust(toPickerWheelValue: "Aberdeen")
xcode error is:
Testing Failure - Internal error: unable to find current value '1 of 152' in possible values
Thanks
You are using it correctly, but the adjust(toPickerWheelValue:) method is buggy, as discussed here: https://forums.developer.apple.com/thread/16104
I agree with Oletha this seems to remain an unfixed bug in the framework.
We could fix the issue at least temporarily by calling
pickerWheel.swipeDown()
before calling
pickerWheel.adjust(toPickerWheelValue: "Value")
Otherwise we received the same crash.
After you displayed picker wheel on screen, you can update the value by:
app.pickerWheels.element.adjustToPickerWheelValue("Updated row value")

How to convert EDAMTimestamp to NSDate with Evernote Cloud SDK for iOS

I tried Evernote Cloud SDK 2.0.6 for iOS. When I fetch the EDAMSyncChunk and the note data from Evernote service, created (and also updated and deleted) property as NSNumber type in EDAMNote instance has following values for example:
1350039844000
765020000
The former seems to be the UNIX time with milliseconds, so I can convert the value to NSDate object, getting "2012-10-12 20:04:04" (JST).
The latter, however, does not seem to be the correct UNIX time because the value cannot be converted to the acceptable time regardless of removing the last three digits:
765020000 ---> "1994-03-30 18:33:20" (JST)
765020 ---> "1970-01-10 05:30:20" (JST)
How can I get the correct time from the latter case? (I doubt that "765020000" results from something like "xxxx765020000" in 32bit environment, though I cannot check the environment now... sorry)
Please help.
Thanks.
on my project, I got it working like this (in swift):
let date = NSDate(EDAMTimestamp: note.created.longLongValue)

get mediaSessionID for the current media playing on chrome cast in Swift on iOS

I'm referring to https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_media_status.html#a45e3eb39e674f5d0dbfd78deef77a1e6
that helps me with the api, but the initializer for the GCKMediaStatus class says:
- (instancetype) initWithSessionID: (NSInteger) mediaSessionID
mediaInformation: (GCKMediaInformation *) mediaInformation
note: this is in Objective-c syntax but Swift works just the same except in Swift language...
Nonetheless I can't seem to figure out how to retrieve the mediaSessionID to be able to initialize an instance of this class to a new variable.
I'm trying to do the following to get me eventually to the method within this class called streamPosition which would go like this:
var mediaStatus = GCKMediaStatus(sessionID: Int, mediaInformation: GCKMediaInformation!)
var currentStreamPosition = mediaStatus.streamPosition()
where Int would be the mediaSessionID NOT the sessionID of the chrome cast (read the additional section below!!) and GCKMediaInformation! would be an instance of the GCKMediaInformation class. (I think) correct me if I'm wrong on either of those parameters.
Then I could use this data. But when I do this the currentStreamPosition I suppose defaults to 0 and thats what I get when I print to the currentStreamPosition variable.
Note: I've already connected to the current playing media and I am able to pause, play, and seek to an arbitrary number within the stream. This all works. So I now I'm connected and everything else works.
use case: I want to be able skip ahead 15 seconds or rewind 15 seconds etc. with the use of this method, but I haven't found anything to help.
also - don't get sessionID confused with mediaSessionID!! I CAN get the sessionID successfully and print it out. My issue is with the mediaSessionID.
additional info: the autocomplete is Xcode says this is the parameters labeled names:
GCKMediaStatus(sessionID: Int, mediaInformation: GCKMediaInformation!)
note the first parameter says sessionID and it is of type int. But on https://developers.google.com/cast/docs/ios_sender if you notice sessionID is of type String! (an optional String).
I think this label was mis-named in Xcode for the autocomplete. I think it should be named mediaSessionID and NOT sessionID since this is what the documentation shows on the first link I provided.
Any help would be much appreciated.
Thanks!
To get the stream position, use the method approximateStreamPosition on GCKMediaControlChannel.

NSTimeZone.localTimeZone().secondsFromGMT crashed

As title said, My app crashed on client side and get reported via Parse crashes report but I just can't reproduce it on my side.
Everything working just fine on both simulator and real device also downloaded app from app store working flawlessly. But I keep getting crash report until today.
Here's the code for get timezone as integer
static var timezone: Int {
get {
return Int(NSTimeZone.localTimeZone().secondsFromGMT/3600) ?? 0
}
}
It shouldn't be any problem there but crash log end at that line or maybe I just missing something there. Please advice if someone hit this before. Any idea is welcome.
I have found that it crashes in Pacific timezone when you cast it to Int. in my case the following fixed the problem
let time = UInt32(NSDate().timeIntervalSince1970 + NSTimeInterval(NSTimeZone.localTimeZone().secondsFromGMT))

MonoTouch DateTime.ToLocalTime does not update when time zone is changed

When I change the time zone on my computer (when testing on the simulator) or on the phone (when testing directly on the phone), DateTime.ToLocalTime() does not return updated results.
I register and successfully receive notification events for UIApplication.Notifications.ObserveSignificantTimeChange. In it I call TimeZoneInfo.ClearCachedData() which allows me to detect the time zone has in fact changed but this has no effect on ToLocalTime(). The DateTime I am converting is definitely of kind Utc (tried DateTime.UtcNow for example).
I tried calling CultureInfo.CurrentCulture.ClearCachedData() as suggested in this question: SetTimeZoneInformation does not update DateTime.Now for another .NET Application. That only causes the application to crash when the CurrentCulture is nulled.
Digging a bit deeper into the implementation of ToLocalTime(), it seems to use the object TimeZone.CurrentTimeZone. This object is reset only when the difference between DateTime.GetNow() and TimeZone.timezone_check. I suspect that TimeZone.timezone_check is not getting updated when TimeZoneInfo.ClearCachedData() is called.
Is there any way I can force ToLocalTime() to take into consideration the time zone change?
You can use DateTimeOffset for this. See also this question.
Edit - What I have working is this:
var dateTimeUtc = new System.DateTime(2013, 2, 4, 21, 30, 0,
System.DateTimeKind.Utc);
var dateTimeOffsetLocal = new System.DateTimeOffset(dateTimeUtc.ToLocalTime());
var formattedLocalTime = string.Format("{0:HH:mm}", dateTimeOffsetLocal);
On my phone my formattedLocalTime changes whenever I change my TimeZone on it, without clearing any cache. I do have to reload the view, but no other tricks.
To display/verify the local TimeZone I use:
var localTimeZone = System.TimeZoneInfo.Local.StandardName;
I hope this somehow points you in the right direction. I don't have any better than this "works on my machine(s)"-anwer.

Resources