@@ -38,6 +38,7 @@ + (void)initialize {
38
38
protectedKeys = PF_SET (PFInstallationKeyDeviceType,
39
39
PFInstallationKeyInstallationId,
40
40
PFInstallationKeyTimeZone,
41
+ PFInstallationKeyLocaleIdentifier,
41
42
PFInstallationKeyParseVersion,
42
43
PFInstallationKeyAppVersion,
43
44
PFInstallationKeyAppName,
@@ -107,6 +108,7 @@ @implementation PFInstallation
107
108
@dynamic installationId;
108
109
@dynamic deviceToken;
109
110
@dynamic timeZone;
111
+ @dynamic localeIdentifier;
110
112
@dynamic channels;
111
113
@dynamic badge;
112
114
@@ -199,6 +201,12 @@ - (void)setTimeZone:(NSString *)timeZone {
199
201
[self _setObject: timeZone forKey: PFInstallationKeyTimeZone onlyIfDifferent: YES ];
200
202
}
201
203
204
+ - (void )setLocaleIdentifier : (NSString *)localeIdentifier {
205
+ [self _setObject: localeIdentifier
206
+ forKey: PFInstallationKeyLocaleIdentifier
207
+ onlyIfDifferent: YES ];
208
+ }
209
+
202
210
- (void )setChannels : (NSArray *)channels {
203
211
[self _setObject: channels forKey: PFInstallationKeyChannels onlyIfDifferent: YES ];
204
212
}
@@ -256,6 +264,7 @@ - (void)_updateAutomaticInfo {
256
264
[self _updateTimeZoneFromDevice ];
257
265
[self _updateBadgeFromDevice ];
258
266
[self _updateVersionInfoFromDevice ];
267
+ [self _updateLocaleIdentifierFromDevice ];
259
268
}
260
269
}
261
270
}
@@ -301,6 +310,37 @@ - (void)_updateVersionInfoFromDevice {
301
310
}
302
311
}
303
312
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
+
304
344
// /--------------------------------------
305
345
#pragma mark - Data Source
306
346
// /--------------------------------------
0 commit comments