简体   繁体   中英

In web-based apps, how do I call a user's IMEI / UDID to the end of my web-based app's URL?

I'm making a pair of website-based apps for both Android and iOS interfaces, and I'm struggling with a part of it. Perhaps you guys could help me out!

I'm using Android Studio and Xcode, and launching the website through WebKit and WK WebView respectively. It's super simple, just an app which calls a website into it directly. No external navigation, nothing but a full-page website. And this part is working great!

But I do have one problem! I don't want my users to get consistently logged out if they close the app, or after a few hours of not using it. I'd like it to stay logged in for them, or to automatically log-in when they use it.

The maker of the website has given me a way to do this through the URL.

Basically, my URL currently is set up like " https://URL.com/x/y/z " and it goes to the website, and that is great, but I need to set it up to be " https://url.com/x/y/z/[insert user's IMEI or UDID here]". That unique ID from their Android device will keep them logged in. I've tested it using my own device with my own IMEI and it works great, but obviously using one specific identifier for everyone will not work. I just need it to call the specific user's IMEI or UDID into the URL, to complete it.

How should I go about this?

I am assuming that you are talking about an Android app that visualizes a website in an activity. On Android, you can retrieve the device's IMEI OR MEID string by calling:

android.telephony.TelephonyManager.getDeviceId().

But be warned, this requires that you add a permission to your manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

You should inform your users why you are requesting this permission.

For iOS/Xcode, you can get the device UUID via UIDevice:

// Swift 4
let uuid = UIDevice.current.identifierForVendor!.uuidString

If you are targeting iOS 11 or newer, Apple introduced Device Check to get a device specific token. I personally haven't used it, but it sounds like it's use case is similar to what you're looking for.

Update: From your comment, here is how'd you include it in the url string.

let urlString = "url.com/x/y/z/" + uuid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM