ui-screen-shooter icon indicating copy to clipboard operation
ui-screen-shooter copied to clipboard

Integrate Simulator Status Magic

Open ZevEisenberg opened this issue 10 years ago • 4 comments

I haven't tested this yet (I'm about to), but if it works, this would be a great dependency to add: https://github.com/shinydevelopment/SimulatorStatusMagic

ZevEisenberg avatar Oct 12 '14 00:10 ZevEisenberg

Simulator Status Magic formats dates like this:

// Set 9:41 time in current localization
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSDate *date = [dateFormatter dateFromString:@"9:41 AM"];
NSString *dateString = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:date]];

When run in conduction with UI Screen Shooter's localization, that still returns 9:41 AM.

When I change Status Magic like this:

// Set 9:41 time in current localization
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
NSDate *date = [dateFormatter dateFromString:@"9:41 AM"];

NSString *preferredLocaleIdentifier = [NSLocale preferredLanguages].firstObject;
if (preferredLocaleIdentifier) {
    dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:preferredLocaleIdentifier];
}

NSString *dateString = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:date]];

Then I get a different string than Apple uses. For example, Apple's site uses this clock on Chinese iPhones: 上午9:41. However, NSDateFormatter, when passed a locale of zh-Hant, seems to be returning 9:41 上午. While this isn’t directly a problem for UI Screen Shooter, it would be nice to figure out why it is different if we are going to use these tools together for localized screenshots.

ZevEisenberg avatar Oct 12 '14 04:10 ZevEisenberg

Posted this to Stack Overflow. Got the feeling I'm going about it wrong. http://stackoverflow.com/questions/26321963/nsdateformatter-results-different-from-apple-cn-screenshots

ZevEisenberg avatar Oct 12 '14 05:10 ZevEisenberg

I fear that the reason for the localization problems is related to this.

@ZevEisenberg, can you see if using this script forces the simulator into the correct locale? I removed it a while back and went with the command line parameter mechanism because that script overwrites the simulator preferences for locale information with PlistBuddy. I wasn't happy with that, but it seems that this is the only way to make it work. I'm curious to know if it still does.

jonathanpenn avatar Oct 12 '14 05:10 jonathanpenn

I'll give it a try, but I believe I'm getting the right locale with the current method. The problem seems to be just getting the right date format string, and I think that may have to be solved with a bunch of .strings files in simulator status magic.

ZevEisenberg avatar Oct 12 '14 06:10 ZevEisenberg