gpt4 book ai didi

swift - SFAuthorizationView - Swift

转载 作者:行者123 更新时间:2023-11-30 10:58:15 26 4
gpt4 key购买 nike

如何在 swift 项目中使用 SFAuthorizationView。我已经尝试创建桥接 header 并导入 SecurityInterface/SFAuthorizationView.h 。我的代码如下。

My reference -https://github.com/dominikhofacker/SFAuthorizationView.

授权 View 和锁定图标出现在我的输出屏幕上。但是当我点击锁定按钮时什么也没有发生。

import Cocoa

class ViewController: NSViewController {

@IBOutlet weak var auth: SFAuthorizationView!

@IBOutlet weak var button: NSButton!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
var items = [ AuthorizationItem(name: kAuthorizationRuleIsAdmin, valueLength: 0, value: nil, flags: 0), ]
var rights = AuthorizationRights(count: UInt32(items.count), items: &items)
auth.setAuthorizationRights(&rights)
auth.setDelegate(self)
auth.updateStatus(nil)
button.isEnabled = isUnlocked()

}

override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}

func isUnlocked() -> Bool {
return auth.authorizationState() == SFAuthorizationViewUnlockedState;
}


override func authorizationViewDidAuthorize(_ view: SFAuthorizationView!) {
button.isEnabled = isUnlocked()
}
override func authorizationViewDidDeauthorize(_ view: SFAuthorizationView!) {
button.isEnabled = isUnlocked()
}
@IBAction func button(_ sender: Any) {
print("hihi")
}

}

最佳答案

似乎您只是忘记禁用 sandbox mode在项目目标功能选项卡

关于swift - SFAuthorizationView - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53703246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com