iOS Question Get country Code

MList

Member
Licensed User
B4X:
Sub GetLanguage As String
    Dim no As NativeObject
    Dim s As String = no.Initialize("NSLocale") _
        .RunMethod("preferredLanguages", Null).RunMethod("objectAtIndex:", Array(0)).AsString
    If s.Length > 2 Then s = s.Substring2(0, 2)
    Return s
End Sub
Sub GetCountry As String
    Dim no As NativeObject
    Dim s As String  = no.Initialize("NSLocale") _
            .RunMethod("currentLocale", Null).RunMethod("objectForKey:", Array("NSLocaleCountryCode")).AsString
    
    Return s
End Sub
Get Country throws an error, GetLanguage works fine
Whats missing ? or what is wrong.
Sorry, I am a newbie to B4i
Thanks a lot
Marion

Application_Start
Error occurred on line: 666 (Main)
Object was not initialized (NSObject)
Stack Trace: (
CoreFoundation <redacted> + 252
libobjc.A.dylib objc_exception_throw + 56
CoreFoundation <redacted> + 0
TC-Transfer -[B4IObjectWrapper object] + 136
TC-Transfer -[B4INativeObject AsString] + 76
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
TC-Transfer +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
TC-Transfer -[B4IShell runMethod:] + 448
TC-Transfer -[B4IShell raiseEventImpl:method:args::] + 1648
TC-Transfer -[B4IShellBI raiseEvent:event:params:] + 1580
TC-Transfer +[B4IDebug delegate:::] + 80
TC-Transfer -[b4i_main _getcountry] + 212
TC-Transfer -[ResumableSub_main_Application_Start resume::] + 1204
TC-Transfer -[b4i_main _application_start:] + 516
CoreFoundation <redacted> + 144
CoreFoundation <redacted> + 292
TC-Transfer +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
TC-Transfer -[B4IShell runMethod:] + 448
TC-Transfer -[B4IShell raiseEventImpl:method:args::] + 2172
TC-Transfer -[B4IShellBI raiseEvent:event:params:] + 1580
TC-Transfer __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib <redacted> + 24
libdispatch.dylib <redacted> + 16
libdispatch.dylib <redacted> + 1068
CoreFoundation <redacted> + 12
CoreFoundation <redacted> + 1924
CoreFoundation CFRunLoopRunSpecific + 436
GraphicsServices GSEventRunModal + 104
UIKitCore UIApplicationMain + 212
TC-Transfer main + 128
libdyld.dylib <redacted> + 4
)
Application_Active
 
Top