是否可以在macOS应用中显示当前用户的用户名?
答案 0 :(得分:18)
您可以使用NSUserName()
功能:
var username = NSUserName()!
答案 1 :(得分:1)
Swift 4.2
let userName = NSUserName()
let fullUserName = NSFullUserName()
答案 2 :(得分:0)
以下对我有用。它是从 this post 复制的。
CKContainer.default().requestApplicationPermission(.userDiscoverability) { (status, error) in
CKContainer.default().fetchUserRecordID { (record, error) in
CKContainer.default().discoverUserIdentity(withUserRecordID: record!, completionHandler: { (userID, error) in
let fullName = (userID?.nameComponents?.givenName)! + " " + (userID?.nameComponents?.familyName)!
})
}
}