목록소스 팁/Objective C, Swift, iOS, macOS (50)
인디노트
ScrollViewReader 사용의 경우이고 import SwiftUI struct ContentView: View { @State var items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] var body: some View { VStack { ScrollViewReader { proxy in List(items, id: \.self) { item in Text("Item \(item)") .id(item) } .onAppear { // Scroll to the last item when the list appears withAnimation { proxy.scrollTo(items.last, anchor: .bottom) } } } Button(action: { // Add an..
- (void)windowDidLoad { [super windowDidLoad]; // 현재 윈도우의 위치와 크기를 가져옵니다. NSWindow *window = [self window]; NSRect windowFrame = [window frame]; // 화면의 중앙 위치를 계산합니다. NSRect screenFrame = [[NSScreen mainScreen] visibleFrame]; CGFloat centerX = NSMidX(screenFrame); CGFloat centerY = NSMidY(screenFrame); // 윈도우를 중앙으로 이동시킵니다. windowFrame.origin.x = centerX - windowFrame.size.width / 2; windowFrame.or..
흔히 xcode 에서 빌드한 앱은 archive 를 해서 배포 파일을 만들어야 다른 맥에서 실행이 된다. 이렇게 되면 Developer ID 로 싸이닝하게되는 것이다. 번거롭다. run script 에 xcode 로 빌드 한 후 다음의 코드싸인 처리하자. codesign --force --sign - "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Contents/MacOS/${PRODUCT_NAME}" 이제 직접 빌드한 app 을 다른 맥에 복사해서 사용할 수 있다. 주의해야 할 것은 배포버전과 싸이닝 값이 다르므로 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 같은것을 처리할 때 대상이 다르기 때문에 ..
이거 어디다 쓰는 물건인고? 하시는 개발자분들 계실거 같은데요. 인증 관련 개발자들 중에서 극히 드문 경우에만 사용합니다. 이 예제에서는 AuthorizationExecuteWithPrivileges를 사용하여 메커니즘을 실행하는 예제이며 자꾸 잊어 버려서 기록용으로 올려 놓습니다. #include OSStatus MyPluginCreate(AuthorizationPluginRef inPlugin, const AuthorizationCallbacks *inCallbacks, AuthorizationPluginRef *outPlugin) { // ... return err; } OSStatus MechanismInvoke(const AuthorizationMechanismId mechanismId, Aut..
#import #import #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:..
Objective-C를 사용하여 macOS에서 관리자 권한을 얻으려면 Authorization Services 프레임워크를 사용해야 합니다. 이를 통해 애플리케이션의 특정 작업을 수행하기 위해 관리자 권한이 필요한 경우 사용자에게 권한을 요청할 수 있습니다. 아래는 Objective-C를 사용하여 Authorization Services 프레임워크를 사용하여 관리자 권한을 요청하는 방법입니다. #import #import int main(int argc, const char * argv[]) { @autoreleasepool { OSStatus status; AuthorizationRef authRef; status = AuthorizationCreate(NULL, kAuthorizationEmptyEn..
// import 필요 #import // ... // 시스템 종료 함수 void ShutDown() { // 예약된 종료 요청을 만듭니다 AuthorizationRef authorizationRef; AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); const char *tool = "/sbin/shutdown"; char *argv[3] = { "-h", "now", NULL }; FILE *pipe = NULL; OSStatus status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthor..
MacOS 10.7 (Lion)부터 Apple은 AuthorizationExecuteWithPrivileges 함수를 더 이상 권장하지 않으며, 대신 SMJobBless 함수를 사용하도록 권장합니다. SMJobBless 함수는 권한이 필요한 작업을 수행하기 위해 Launch Services를 사용하여 승인된 helper 도구를 설치하고 실행하는 기능을 제공합니다. 아래는 SMJobBless 함수를 사용하여 승인된 helper 도구를 설치하고 실행하는 예시 코드입니다: // import 필요 #import // ... // helper 도구의 Bundle ID NSString *helperBundleID = @"com.example.helper"; // helper 도구를 설치하기 위한 인증 객체 생성 N..
퍼옴 : https://www.hostmyapple.com/blog/10-ways-to-restart-shutdown-your-mac Today I want to show you a few different ways you can restart or shutdown your Mac. Listed below are 10 methods you can use based on the status of your Mac. A few of the approaches for shutting down or restarting may be preferred in most situations, whereas some of the methods are better to use when your Mac becomes unres..
NSLocalizedDescription=The certificate for this server is invalid. You might be connecting to a server that is pretending to be “10.10.145.123” which could put your confidential information at risk. 다음과 같은 구현을 해 주자. extension URLSessionDelegate { func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposit..