Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

So,How to make saving device id at start point and them accessible to all classes for async request?

In app,didFinishLaunchingWithOptions,I will add the following code let 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”)
}

And I want to access that private var at everywhere in the UIViewController class.

class ViewController : UIViewController {
     let deviceID = //some private var with getter?
}

Is there any idea that i can do in swift?using Apple Access Control?

And that problem is connected to that question : Getting Device ID is not unique

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
177 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...