Add nil check for country code and language code (flutter/engine#4732)

NSLocale objectForKey: may return nil for NSLocaleLanguageCode and
NSLocateCountryCode in certain cases.

This adds a defensive nil check for such cases.
This commit is contained in:
Chris Bracken
2018-03-01 13:46:22 -08:00
committed by GitHub
parent 4294850976
commit 37165bd6cc

View File

@@ -724,7 +724,8 @@ static inline blink::PointerData::DeviceKind DeviceKindFromTouchType(UITouch* to
NSLocale* currentLocale = [NSLocale currentLocale];
NSString* languageCode = [currentLocale objectForKey:NSLocaleLanguageCode];
NSString* countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
[_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]];
if (languageCode && countryCode)
[_localizationChannel.get() invokeMethod:@"setLocale" arguments:@[ languageCode, countryCode ]];
}
#pragma mark - Set user settings