nslocale

How to map MCC + MNC to users phone country code in iOS objective-C without using Location info?

谁说胖子不能爱 提交于 2019-12-06 08:48:01
I want the actual country code of the users phone number without prompting the user for Location Permission. How do I get it? Here is the code I use to get the MCC and MNC CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [networkInfo subscriberCellularProvider]; NSString *mcc = [carrier mobileCountryCode]; NSString *mnc = [carrier mobileNetworkCode]; I get MCC - 310 and MNC - 410 which corresponds to AT&T USA. But what I want is '+1' the country code dialing for the user. Alternatively, Is it possible to do it with NSLocale? Try this NSLocale

wrong decimal separator with NSDecimalNumber in iOS

China☆狼群 提交于 2019-12-06 04:38:55
问题 I tried to output the description of a decimal number with the correct decimal separator in the following way: NSString* strValue = @"9.94300"; NSDecimalNumber* decimalNumber = [NSDecimalNumber decimalNumberWithString: strValue]; NSLocale* locale = [NSLocale currentLocale]; NSLog(@"%@", [locale localeIdentifier]); NSLog(@"%@", [decimalNumber descriptionWithLocale: locale] ); The output is: de_DE 9.943 The decimal separator should be ',' instead of '.' for this locale. Where is the error? How

What locale argument to pass to NSDecimalNumber +decimalNumberWithString:locale: so it always works with NSString's using the dot (.) decimal mark?

烈酒焚心 提交于 2019-12-06 01:26:59
问题 I have an NSString which I want to convert into an NSDecimalNumber . The string is received from a server and is always formatted using the en_US locale like XXX.YYY and not like XXX,YYY . I want to create an NSDecimalNumber which accepts XXX.YYY regardless of the locale the user. The number is never displayed to the user, it's used to do internal math. Normally you'd do something like this: NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithString:@"1.234"]; However, if the user is

How do I get current application locale?

♀尐吖头ヾ 提交于 2019-12-05 16:49:21
问题 I need to get current locale. Not user locale but my application locale. Let's say my application has two localizations (in project settings): English (default) and French. If user sets French language on iPhone then my application will display French interface. If user sets German language on iPhone then my application will display English interface (because English is default). So how do I get current application locale that is showing right now? Thanks in advance. 回答1: The selected answer

Display currency symbols using currency codes in iPhone SDK

↘锁芯ラ 提交于 2019-12-04 20:38:06
Actually, I want to display the currency symbols of all currency codes and I'm using code like this,but i only get "$" symbols -(void) showCurrenciesList { NSNumberFormatter *numFormatter = [[NSNumberFormatter alloc] init]; [numFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; //[numFormatter setLocale: [NSLocale currentLocale]]; NSMutableArray *aryAllCurrencies = [[NSMutableArray alloc] init]; //NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier: @"en_US"] autorelease]; NSArray *currencyArray = [NSLocale ISOCurrencyCodes]; NSLog(@"Currency array : %@",currencyArray); for

xcode 6.1 iOS 8.1 NSLocale displayNameForKey NSLocaleIdentifier return nil

陌路散爱 提交于 2019-12-04 16:09:25
问题 - (NSString *)countryNameByCode:(NSString*)countryCode { NSString *identifier = [NSLocale localeIdentifierFromComponents:@{NSLocaleCountryCode: countryCode}]; NSString *countryName = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:identifier]; return countryName; } This returned nil . Why? 回答1: This is a known Apple issue for iOS 8.1 simulator only - not reproducible on 8.1 devices. See below issue description from Xcode 6.1 release notes: Localization and Keyboard

wrong decimal separator with NSDecimalNumber in iOS

此生再无相见时 提交于 2019-12-04 10:49:21
I tried to output the description of a decimal number with the correct decimal separator in the following way: NSString* strValue = @"9.94300"; NSDecimalNumber* decimalNumber = [NSDecimalNumber decimalNumberWithString: strValue]; NSLocale* locale = [NSLocale currentLocale]; NSLog(@"%@", [locale localeIdentifier]); NSLog(@"%@", [decimalNumber descriptionWithLocale: locale] ); The output is: de_DE 9.943 The decimal separator should be ',' instead of '.' for this locale. Where is the error? How can I output the correct decimal separator depending on the local? @TriPhoenix: Yes I'm running iOS 5.

What locale argument to pass to NSDecimalNumber +decimalNumberWithString:locale: so it always works with NSString's using the dot (.) decimal mark?

[亡魂溺海] 提交于 2019-12-04 05:08:05
I have an NSString which I want to convert into an NSDecimalNumber . The string is received from a server and is always formatted using the en_US locale like XXX.YYY and not like XXX,YYY . I want to create an NSDecimalNumber which accepts XXX.YYY regardless of the locale the user. The number is never displayed to the user, it's used to do internal math. Normally you'd do something like this: NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithString:@"1.234"]; However, if the user is running the fr_FR locale of Mac OS X, that will break. en_US will interpret it as one point two three four ,

NSDateformatter setDateFormat according to currentLocale

回眸只為那壹抹淺笑 提交于 2019-12-03 11:57:45
I'm going mad with, probably, a stupid problem. I have 3 strings: year, month and day. I need to have a date in the right format based on currentLocale, so i.e. if currentLocale localeIdentifier is en_US my dateFormat should be: MMM/dd/yyyy if it's fr_FR the dateFormat should be dd/MMM/yyyy I don't think the only way to do this is to get currentLocale localeIdentifier and start with a bunch of if then. Thanks in advance. Max Look at NSDateComponents to create an NSDate, then use NSDateFormatter to format it. NSDateFormatter uses the current locale to format dates, based on the format style (e

NSLocale currency symbol, show before or after amount value

こ雲淡風輕ζ 提交于 2019-12-03 11:37:56
I am using StoreKit to implement an in app purchase store in my application. I have a custom design and it means that the value of the price should be white and large, and the currency symbol smaller, darker and aligned to the top of the price value. I can get the currency symbol without any problems by using the NSLocale in SKproduct 's priceLocale property, and the value of the price in the price property. My problem is knowing when I should put the currency symbol before the price and when to put it after the price. Examples: $5,99 0,79€ I could easily use the NSNumberFormatter to get this