iOS Question How to get the country Code

Discussion in 'iOS Questions' started by Brian Robinson, Feb 6, 2015.

Similar threads

B4A Tutorial [B4X] B4XTable with custom cells layout
B4i Tutorial Notifications with actions
B4i Code Snippet Monitor http requests progress
B4i Tutorial iBeacons
B4i Code Snippet Full screen apps
  1. Brian Robinson

    Brian Robinson Active Member Licensed User

    Hi All,

    I am attempting to get the country code of the device based off the ISO value.

    I found this bit of code:

    Code:
    NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
    and I have attempted to write it like this, but I am unsure how to specify the NSLocaleCountryCode value. This is what I have so far:
    Code:
    Private Sub GetCountryCode As String
        
    Dim no As NativeObject
        
    Return no.Initialize("NSLocale") _
            .RunMethod(
    "currentLocale"Null).RunMethod("objectForKey:"Array("NSLocaleCountryCode")).AsString
    End Sub
    Any ideas?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Use the new inline Objective C feature. It is simpler:
    Code:
    Dim nativeMe As NativeObject = Me
       
    Log(nativeMe.RunMethod("getCountryCode"Null).AsString)
    End Sub

    #If OBJC
    - (NSString*) getCountryCode {
       NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
       return countryCode;
    }
    #end if
     
  3. Brian Robinson

    Brian Robinson Active Member Licensed User

    Ahhhhh... Of course...

    Thanks Erel.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice