일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- MSYS2
- 애플
- 안드로이드
- kmip
- 인증
- otpkey
- MFA
- Android
- FIDO2
- OSX
- css
- SwiftUI
- albumbook
- SWIFT
- Nodejs
- fido
- Xcode
- 앨범북
- 앱리소스
- git
- 2FA
- apple
- MYSQL
- 앱스토어
- WebAuthn
- appres
- openssl
- OTP
- SSH
- SSL
Archives
- Today
- Total
인디노트
SFAuthorizationPluginView 본문
#import <Security/Security.h>
#import <SecurityInterface/SecurityInterface.h>
#import "MyAuthorizationView.h"
@interface MyAuthorizationView ()
@property (nonatomic, strong) SFAuthorization *authorization;
@property (nonatomic, strong) IBOutlet NSButton *myButton;
@end
@implementation MyAuthorizationView
- (instancetype)initWithFrame:(NSRect)frameRect {
self = [super initWithFrame:frameRect];
if (self) {
[NSBundle loadNibNamed:@"MyAuthorizationView" owner:self];
[self addSubview:self.view];
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
self.myButton.title = @"Authorize";
}
- (IBAction)myButtonClicked:(id)sender {
if (self.authorization == nil) {
self.authorization = [SFAuthorization authorization];
}
AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights;
AuthorizationRef authRef = [self.authorization authorizationRef];
AuthorizationItem authItem = {kAuthorizationEnvironmentPassword, 0, NULL, 0};
AuthorizationRights authRights = {1, &authItem};
OSStatus status = AuthorizationCopyRights(authRef, &authRights, NULL, flags, NULL);
if (status == errAuthorizationSuccess) {
NSLog(@"Authorization granted!");
// perform the action you want to do after successful authorization
} else {
NSLog(@"Authorization denied!");
}
}
@end
#import <Cocoa/Cocoa.h>
#import <SecurityInterface/SecurityInterface.h>
@interface MyAuthorizationView : SFAuthorizationPluginView
@property (nonatomic, strong) NSView *view;
@end
MyAuthorizationView.nib 파일의 구성 요소
Window
Title: MyAuthorizationView
Class: SFAuthorizationPluginView
Autosave name: MyAuthorizationView
View
Class: NSView
Autosizing: All Margins
Frame: (0, 0, 240, 120)
Button
Title: Authorize
Class: NSButton
Autosizing: None
Frame: (20, 20, 200, 80)
Target: MyAuthorizationView
Action: myButtonClicked:
File's Owner
Class: MyAuthorizationView
#import <SecurityInterface/SFAuthorizationPluginView.h>
반응형
'소스 팁 > Objective C, Swift, iOS, macOS' 카테고리의 다른 글
xcode 에서 직접 app 에 서명 (0) | 2023.04.04 |
---|---|
MechanismInvoke 를 구현하는 샘플 (0) | 2023.03.31 |
macOS 관리자 권한 얻어오기 (0) | 2023.03.29 |
Mac에서 Objective-C를 사용하여 시스템을 종료하는 코드 (0) | 2023.03.29 |
AuthorizationExecuteWithPrivileges 대신 SMJobBless (0) | 2023.03.29 |
Comments