@@ -38,6 +38,7 @@ + (void)initialize {
3838 protectedKeys = PF_SET (PFInstallationKeyDeviceType,
3939 PFInstallationKeyInstallationId,
4040 PFInstallationKeyTimeZone,
41+ PFInstallationKeyLocaleIdentifier,
4142 PFInstallationKeyParseVersion,
4243 PFInstallationKeyAppVersion,
4344 PFInstallationKeyAppName,
@@ -107,6 +108,7 @@ @implementation PFInstallation
107108@dynamic installationId;
108109@dynamic deviceToken;
109110@dynamic timeZone;
111+ @dynamic localeIdentifier;
110112@dynamic channels;
111113@dynamic badge;
112114
@@ -199,6 +201,12 @@ - (void)setTimeZone:(NSString *)timeZone {
199201 [self _setObject: timeZone forKey: PFInstallationKeyTimeZone onlyIfDifferent: YES ];
200202}
201203
204+ - (void )setLocaleIdentifier : (NSString *)localeIdentifier {
205+ [self _setObject: localeIdentifier
206+ forKey: PFInstallationKeyLocaleIdentifier
207+ onlyIfDifferent: YES ];
208+ }
209+
202210- (void )setChannels : (NSArray *)channels {
203211 [self _setObject: channels forKey: PFInstallationKeyChannels onlyIfDifferent: YES ];
204212}
@@ -256,6 +264,7 @@ - (void)_updateAutomaticInfo {
256264 [self _updateTimeZoneFromDevice ];
257265 [self _updateBadgeFromDevice ];
258266 [self _updateVersionInfoFromDevice ];
267+ [self _updateLocaleIdentifierFromDevice ];
259268 }
260269 }
261270}
@@ -301,6 +310,37 @@ - (void)_updateVersionInfoFromDevice {
301310 }
302311}
303312
313+ /* !
314+ @abstract Save localeIdentifier in the following format: [language code]-[COUNTRY CODE].
315+
316+ @discussion The language codes are two-letter lowercase ISO language codes (such as "en") as defined by
317+ <a href="http://en.wikipedia.org/wiki/ISO_639-1">ISO 639-1</a>.
318+ The country codes are two-letter uppercase ISO country codes (such as "US") as defined by
319+ <a href="http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3">ISO 3166-1</a>.
320+
321+ Many iOS locale identifiers don't contain the country code -> inconsistencies with Android/Windows Phone.
322+ */
323+ - (void )_updateLocaleIdentifierFromDevice {
324+ NSLocale *currentLocale = [NSLocale currentLocale ];
325+ NSString *language = [currentLocale objectForKey: NSLocaleLanguageCode ];
326+ NSString *countryCode = [currentLocale objectForKey: NSLocaleCountryCode ];
327+
328+ if (language.length == 0 ) {
329+ return ;
330+ }
331+
332+ NSString *localeIdentifier = nil ;
333+ if (countryCode.length > 0 ) {
334+ localeIdentifier = [NSString stringWithFormat: @" %@ -%@ " , language, countryCode];
335+ } else {
336+ localeIdentifier = language;
337+ }
338+
339+ if (localeIdentifier.length > 0 && ![localeIdentifier isEqualToString: self .localeIdentifier]) {
340+ self.localeIdentifier = localeIdentifier;
341+ }
342+ }
343+
304344// /--------------------------------------
305345#pragma mark - Data Source
306346// /--------------------------------------
0 commit comments