SFAuthorizationView - Swift

loading...


0

如何在swift项目中使用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")
}

}
1回答

  • 0

    好像你只是忘了在项目目标的Capabilities选项卡上禁用sandbox mode

评论

loading...

暂时没有评论!