Unique ID for mobile device FMX

Viewed 377

What is a good way to create a unique ID for mobile devices (iOS and Android) in a C++Builder FMX app?

In my case, I just want to let my app users vote, but only once per device (even if they delete the app and reinstall it). They stay anonymous, but just can't vote more than once.

I know Apple came out with DeviceCheck for Swift, but I don't know how to use it in C++.

iOS 11: The DeviceCheck API

DeviceCheck API - Unique Identifier for the iOS Devices

1 Answers

Update: This solution targets Android devices. I have no experience with iOS devices.

Original answer: It may be way too late but here's my solution using _di_JTelephonyManager

_di_JObject obj;
_di_JTelephonyManager tm;
UnicodeString id;

try {
    obj = SharedActivityContext()->getSystemService(TJContext::JavaClass>TELEPHONY_SERVICE);
    if (obj) {
        tm = TJTelephonyManager::Wrap(static_cast<_di_ILocalObject>(obj)->GetObjectID());
        if (tm) {
            //only if SIM Card is in device:
            //id = JStringToString(tm->getSubscriberId());

            //will get IMEI or MEID number
            id = JStringToString(TJSettings_Secure::JavaClass->getString
                (SharedActivity()->getContentResolver(),
                TJSettings_Secure::JavaClass->ANDROID_ID));
        }
    }
}
catch (Exception &e) {
    //catch exceptions
}

Hope it is helpful :)

Related