如何在快速项目中使用SFAuthorizationView。我已经尝试过通过创建桥接头文件并导入SecurityInterface / SFAuthorizationView.h来进行尝试。我的代码如下。


  我的参考-https://github.com/dominikhofacker/SFAuthorizationView


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

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/

10-12 14:39