用户卸载并重新安装时,设备UUID不是唯一的 [英] Device UUID not unique when user uninstall and re-install

查看:72
本文介绍了用户卸载并重新安装时,设备UUID不是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个系统,每个用户只能安装两个设备的应用程序.当用户卸载并在同一设备上再次重新安装时,会发生此问题.因此,当应用程序检查到Web服务时,它将生成新的UUID.

I have a system where each user allowed to install apps for two devices only. The issue is happened when user uninstall and reinstall again on the same device. So it will generate new UUID and when the apps check to web service.

应用程序将发送UUID和登录ID,以检查具有该登录ID的用户是否已安装在两个以上的设备中.我使用的是真实的iPhone和iPad设备,而不是模拟器.我不确定生产环境.目前,这些应用是通过Apple TestFlight和AppStore分发配置文件分发的.

The apps will send UUID and login id in order to check if the user with that login id has installed in more than two devices. I am using real iPhone and iPad device, not using simulator. I am not sure for production environment. Currently the apps is distributed using Apple TestFlight using AppStore Distribution profile.

我用此生成uuid

let uuid = UIDevice.currentDevice().identifierForVendor!.UUIDString

谢谢.

推荐答案

您需要使用钥匙串:(要显示JNKeychain,您需要在pod文件 pod'JNKeychain'中输入新的字符串).这将确保您,如果不更改捆绑标识符,您将始终拥有唯一设备ID(即使删除应用后该ID也将保持不变).我曾经用过,当用户在我们的应用程序中被永久禁止时,即使删除了该应用程序,他也无法使用其他帐户进入该应用程序.

You need to use keychain: (to be able to imort JNKeychain you need to enter a new string in your pod file pod 'JNKeychain'). This will guaranty you that if you don't change you bundle identifier, you will always have a uniq device id (that will stay the same even after deleting your app). I used that when user was banned forever in our application, he couldn't enter the app even with different account even after deleting the app.

import UIKit
import JNKeychain

class KeychainManager: NSObject {
    static let sharedInstance = KeychainManager()

    func getDeviceIdentifierFromKeychain() -> String {

        // try to get value from keychain
        var deviceUDID = self.keychain_valueForKey("keychainDeviceUDID") as? String
        if deviceUDID == nil {
            deviceUDID = UIDevice.current.identifierForVendor!.uuidString
            // save new value in keychain
            self.keychain_setObject(deviceUDID! as AnyObject, forKey: "keychainDeviceUDID")
        }
        return deviceUDID!
    }

    // MARK: - Keychain

    func keychain_setObject(_ object: AnyObject, forKey: String) {
        let result = JNKeychain.saveValue(object, forKey: forKey)
        if !result {
            print("keychain saving: smth went wrong")
        }
    }

    func keychain_deleteObjectForKey(_ key: String) -> Bool {
        let result = JNKeychain.deleteValue(forKey: key)
        return result
    }

    func keychain_valueForKey(_ key: String) -> AnyObject? {
        let value = JNKeychain.loadValue(forKey: key)
        return value as AnyObject?
    }
}

这篇关于用户卸载并重新安装时,设备UUID不是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆