beno
beno

Reputation: 2190

setlocale works in iOS Simulator but fails on device

Unlike the author of this previous question, I'm having the opposite problem. I'm attempting to make use of a component written in C++ in my iPad application that uses setlocale() from the standard C library. When running via the simulator (either i386 or x86_64), I'm able to set a locale successfully and get an expected return value:

(lldb) p (const char *)setlocale(2, "ja_JP")
(const char *) $1 = 0x000000010e776bd0 "ja_JP"

However, when running on a device (on either iOS8 or iOS9, on both armv7 and arm64 devices), this call always seems to fail and return null.

(lldb) p (const char *)setlocale(2, "ja_JP")
(const char *) $0 = 0x00000000

Actually setting the region and language on the iOS device doens't seem to make a difference either.

Is this an example of something like iOS9 preventing the use of sysctl(), or am I missing something bigger here?

Upvotes: 1

Views: 256

Answers (1)

beno
beno

Reputation: 2190

This was actually answered on the Apple Dev Forums recently, sharing it here as well:

The problem here is not setlocale per se, but rather in reading the locale in the first place. Notably, newlocale also returns NULL when you call it with similar parameters. This fails because no C-style locales are available to you on iOS. On the simulator this works because the locale code picks up the locale data from OS X (in /usr/share/locale). I’m not sure if this directory is populated on iOS (I suspect not) but that doesn’t matter because the sandbox won’t let your process get to it.

Upvotes: 2

Related Questions