1

TLDR: Is there is any native way to access the Titanium.App.Properties for both Android and iOS?

I am working on a project where the original app was made with Titanium, and the new updated version is built with Xamarin.

The original developers thought it would be smart to save a Device Token in the Titanium.App.Properties that would be used to access all the users history and purchases.

The device token is not stored anywhere else, so the only way to get to it is through Titanium.App.Properties.

I have the key they used to store the token. So my question is, is there is any native way to access the Titanium.App.Properties for both Android and iOS?


From this doc there is a paragraph: "Both iOS and Android store app properties in special files on the filesystem. Natively, iOS properties are known as NSUserDefaults, which are stored in .plist files in the application's library directory. Android stores them in standard xml text files at /data/data/com.domainname.appname/shared_prefs/titanium.xml. Titanium provides a uniform means to set and get app properties via the Titanium.App.Properties API."

From this SO question it sounds like a module needs to be used: "Other iOS applications cannot access these properties and native Android modules must use the Titanium module API TiApplication.getAppProperties method to access these properties."

c.lamont.dev
  • 693
  • 1
  • 6
  • 14

2 Answers2

3

For Android the Titanium properties are stored in the shared preferences with the path titanium.

ISharedPreferences TitaniumSharedPreferences = CrossCurrentActivity.Current.Activity.GetSharedPreferences("titanium", Android.Content.FileCreationMode.Private);

Then simply use the shared preference to get any property you need.

var userToken = TitaniumSharedPreferences.GetString("UserToken", string.Empty);


For iOS it is simpler, it just uses the NSUserDefaults.

var userToken = NSUserDefaults.StandardUserDefaults.StringForKey("UserToken");

c.lamont.dev
  • 693
  • 1
  • 6
  • 14
0

For Android the TiProperties.java file says:

Instantiates the private SharedPreferences collection with the given name and context.

  • This means no other Android application will have access to they keys and values.

You say you use the token to get a history. Is that coming from a server? So is the token send to the server to do the request?

On the other hand: do you own the source code of the Ti app? Create an update that will store the token in some other way.

Community
  • 1
  • 1
miga
  • 3,997
  • 13
  • 45
  • 1
    Thanks for the answer. As it is an update to a current app I guess it is not classed as an "other Android application". From my answer I managed to get the property. – c.lamont.dev Feb 18 '19 at 19:07
  • good to know that you've found a way. With the same key/bundle identifier it is technically the same app, even if you change the whole app. – miga Feb 19 '19 at 17:37