问题描述
我想迅速获得所有类级别的设备ID,每次进行异步调用时,设备ID都将作为参数包含在其中.而且我对Apple Access Control的了解还不清楚,所以,我真的需要帮助
I want to get device ID in at all classes level in swift which will be included as parameter every time async call made.And I really don't get clearly about Apple Access Control.So,I really need help
那么,如何在开始时使保存的设备ID可供所有类访问,以进行异步请求?
So,How to make saving device id at start point and them accessible to all classes for async request?
在应用程序中,didFinishLaunchingWithOptions,我将添加以下代码假设钥匙串是我存储价值的图书馆
In app,didFinishLaunchingWithOptions,I will add the following codelet say keychain is the library where i store value
if keychain.get("deviceID") == nil{
keychain.set(UIDevice.currentDevice().identifierForVendor!.UUIDString,forKey : "deviceID")
//some private var deviceID = keychain.get("deviceID")
}
else{
some private var deviceID = keychain.get("deviceID")
}
我想在UIViewController类的任何地方访问该私有变量.
And I want to access that private var at everywhere in the UIViewController class.
class ViewController : UIViewController {
let deviceID = //some private var with getter?
}
有什么想法可以使用Apple Access Control快速完成吗?
Is there any idea that i can do in swift?using Apple Access Control?
该问题与该问题有关:获取设备ID不是唯一的
And that problem is connected to that question : Getting Device ID is not unique
推荐答案
将您的deviceID定义为静态,您将可以在任何地方访问它
define your deviceID as static and you will be able to access it everywhere
在您启动钥匙串的代码之后,在某个类中将其设置为静态
after your code to initiate the keychain, set it as a static at some class
class DeviceArg {
static var deviceId = keychain.get("deviceID")
}
// some other place in the code
let check = DeviceArg.deviceId //get deviceId
这篇关于快速使用访问控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!