快速使用访问控制?

编程入门 行业动态 更新时间:2024-10-27 05:28:12
本文介绍了快速使用访问控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想迅速获得所有类级别的设备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 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") }

我想在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

更多推荐

快速使用访问控制?

本文发布于:2023-11-26 04:41:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632663.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:访问控制   快速

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!