{"id":6129,"library":"pyobjc-framework-localauthenticationembeddedui","title":"PyObjC LocalAuthenticationEmbeddedUI Framework","description":"This library provides Python wrappers for Apple's LocalAuthenticationEmbeddedUI framework on macOS. It's part of the larger PyObjC project, which serves as a bridge between Python and Objective-C, enabling Python scripts to interact with and extend macOS Cocoa libraries. The project is actively maintained with frequent releases.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","pyobjc","bindings","framework","security","biometrics","localauthentication","embedded-ui"],"install":[{"cmd":"pip install pyobjc-framework-localauthenticationembeddedui","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This is a framework wrapper built on top of the PyObjC core bridge.","package":"pyobjc-core","optional":false}],"imports":[{"note":"Primary view for embedded authentication UI.","symbol":"LAAuthenticationView","correct":"from LocalAuthenticationEmbeddedUI import LAAuthenticationView"},{"note":"Protocol for handling authentication view results.","symbol":"LAAuthenticationViewDelegate","correct":"from LocalAuthenticationEmbeddedUI import LAAuthenticationViewDelegate"},{"note":"Used to evaluate authentication policies, typically alongside LAAuthenticationView.","symbol":"LAContext","correct":"from LocalAuthentication import LAContext"}],"quickstart":{"code":"import objc\nfrom AppKit import NSApplication, NSWindow, NSView, NSRect, NSButton, NSAppDelegate, NSApp\nfrom Foundation import NSObject, NSSelectorFromString, NSLog\nfrom LocalAuthenticationEmbeddedUI import LAAuthenticationView, LAAuthenticationViewDelegate\nfrom LocalAuthentication import LAContext, LAPolicy, LAError\n\n\nclass AuthenticationDelegate(NSObject, LAAuthenticationViewDelegate):\n    def authenticationView_didCompleteWithResult_error_(self, view, result, error):\n        if error:\n            NSLog(f\"Authentication failed with error: {error.localizedDescription()}\")\n            if error.code() == LAError.UserCancel: # LAError.UserCancel is part of LAError, not LAError.Code.UserCancel\n                NSLog(\"User cancelled authentication.\")\n        elif result:\n            if result == 1: # Assuming LAAuthenticationResult.Success is 1. Check Apple docs for exact enum values.\n                NSLog(\"Authentication successful!\")\n            else:\n                NSLog(\"Authentication completed with unknown result.\")\n        else:\n            NSLog(\"Authentication completed, but no result or error.\")\n\n\nclass AppDelegate(NSObject):\n    def applicationDidFinishLaunching_(self, notification):\n        # Create a window\n        self.window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(\n            NSRect((200, 300), (400, 200)),\n            (1 << 0 | 1 << 1 | 1 << 3 | 1 << 8), # Titled, Closable, Miniaturizable, Resizable\n            2, # NSBackingStoreBuffered\n            False\n        )\n        self.window.setTitle_(\"PyObjC LAEmbeddedUI Example\")\n        self.window.makeKeyAndOrderFront_(None)\n\n        # Create a content view\n        content_view = NSView.alloc().init().autorelease()\n        self.window.setContentView_(content_view)\n\n        # Create LAAuthenticationView\n        self.auth_view = LAAuthenticationView.alloc().initWithFrame_(NSRect((50, 50), (300, 100)))\n        content_view.addSubview_(self.auth_view)\n\n        # Set delegate and context\n        self.delegate = AuthenticationDelegate.alloc().init()\n        self.auth_view.setDelegate_(self.delegate)\n\n        # Create LAContext (from LocalAuthentication framework)\n        self.la_context = LAContext.alloc().init()\n        self.auth_view.setContext_(self.la_context)\n\n        # Start authentication (LAAuthenticationView will start when added to view hierarchy with context)\n        # It might also need an explicit call like evaluatePolicy_localizedReason_reply_ from LAContext\n        # but for embedded UI, setting the context and delegate is often enough to trigger its display.\n        NSLog(\"LAAuthenticationView added. Awaiting user interaction.\")\n\n\nif __name__ == '__main__':\n    app = NSApplication.sharedApplication()\n    delegate = AppDelegate.alloc().init()\n    NSApp().setDelegate_(delegate)\n    app.run()","lang":"python","_review":true,"description":"This quickstart demonstrates how to instantiate and use `LAAuthenticationView` for embedded biometric authentication within a basic macOS Cocoa application. It sets up an `NSApplication`, a window, and integrates the `LAAuthenticationView` with a custom delegate to handle authentication results. Note that `LAAuthenticationView` requires a running macOS application context to be visible and functional. The `LAContext` object is imported from the `LocalAuthentication` framework, which works in conjunction with the UI component. The exact enum values for `LAAuthenticationResult` might need to be verified against Apple's latest documentation.","_review_reason":"The exact `LAAuthenticationResult` enum values (e.g., 1 for success) are assumed and should be verified against Apple's documentation. A fully functional UI example within a JSON constraint is challenging; this provides the core interaction pattern, but running it requires a macOS environment with PyObjC installed and potentially a build step (like py2app) for a standalone app."},"warnings":[{"fix":"Upgrade Python to 3.10 or later, or downgrade `pyobjc-framework-localauthenticationembeddedui` to a compatible version (e.g., `pip install 'pyobjc-framework-localauthenticationembeddedui<12.0'`).","message":"PyObjC v12.0 dropped support for Python 3.9. Users on Python 3.9 or earlier should use PyObjC v11.x or upgrade their Python version.","severity":"breaking","affected_versions":">=12.0"},{"fix":"Upgrade Python to 3.9 or later, or downgrade `pyobjc-framework-localauthenticationembeddedui` to a compatible version (e.g., `pip install 'pyobjc-framework-localauthenticationembeddedui<11.0'`).","message":"PyObjC v11.0 dropped support for Python 3.8. Users on Python 3.8 or earlier should use PyObjC v10.x or upgrade their Python version.","severity":"breaking","affected_versions":">=11.0"},{"fix":"Review code that relies on specific reference counting behavior during object initialization. Adapt to the new ARC-compliant model, which correctly models `init` family methods stealing and returning a new reference.","message":"PyObjC v11.1 changed the reference counting behavior for initializer methods to align with `clang`'s Automatic Reference Counting (ARC) documentation. This might alter how references to `self` are handled during object initialization.","severity":"breaking","affected_versions":">=11.1"},{"fix":"Consult Apple's developer documentation for `LocalAuthenticationEmbeddedUI` and related frameworks (like `LocalAuthentication`) when working with these Python bindings.","message":"PyObjC framework wrappers, including LocalAuthenticationEmbeddedUI, generally do not include their own documentation. Developers must refer to Apple's official documentation for the `LocalAuthenticationEmbeddedUI` framework to understand API usage, class methods, and protocols.","severity":"gotcha","affected_versions":"All"},{"fix":"If using Python 3.13, disable experimental free-threading (if applicable) or use PyObjC in a standard single-interpreter thread mode.","message":"As of PyObjC v10.3, the library does not support the experimental free-threading feature introduced in Python 3.13. Running PyObjC with free-threading enabled may lead to undefined behavior or crashes.","severity":"gotcha","affected_versions":">=10.3 (with Python 3.13+)"},{"fix":"If previously relying on `os.fspath()` with Cocoa URLs, ensure your code correctly handles the new behavior, where it now works for local paths but raises `TypeError` for non-local URLs.","message":"In v10.1, the behavior of `os.fspath()` for Cocoa URLs (NSURL, CFURLRef) referring to local filesystem paths was changed. It now works correctly, while `TypeError` is raised for other URLs.","severity":"gotcha","affected_versions":">=10.1"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}