{"id":6065,"library":"pyobjc-framework-adservices","title":"PyObjC AdServices Framework","description":"PyObjC provides Python wrappers for the \"AdServices\" framework on macOS, allowing Python scripts to interact with Apple's Objective-C APIs for ad attribution. This specific package, `pyobjc-framework-adservices`, enables access to the AdServices framework. PyObjC is actively maintained with frequent releases, often synchronized with macOS SDK updates, ensuring compatibility with the latest Apple operating systems and developer tools. The current version is 12.1.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macOS","frameworks","objective-c","adservices","bindings","apple"],"install":[{"cmd":"pip install pyobjc-framework-adservices","lang":"bash","label":"Install AdServices bindings"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, essential for all PyObjC framework bindings.","package":"pyobjc-core"}],"imports":[{"note":"PyObjC maps macOS frameworks directly to Python packages with the same name.","symbol":"AdServices","correct":"import AdServices"},{"note":"The primary class for requesting attribution tokens within the AdServices framework.","symbol":"AAAttribution","correct":"from AdServices import AAAttribution"}],"quickstart":{"code":"import AdServices\nimport objc\nfrom Foundation import NSLog\nfrom PyObjCTools import AppHelper\n\ndef attribution_completion_handler(token, error):\n    \"\"\"Callback function for the attribution token request.\"\"\"\n    if error:\n        NSLog(\"Error requesting AdServices attribution token: %@\", error)\n    else:\n        NSLog(\"AdServices Attribution Token: %@\", token)\n    AppHelper.stopEventLoop() # Stop the event loop after receiving the token\n\ndef request_token():\n    \"\"\"Initiates the request for an AdServices attribution token.\"\"\"\n    NSLog(\"Requesting AdServices attribution token...\")\n    # The Objective-C method 'requestAttributionTokenWithCompletionHandler:'\n    # translates to 'requestAttributionTokenWithCompletionHandler_' in PyObjC\n    # (note the trailing underscore for methods that take blocks/callbacks).\n    AdServices.AAAttribution.requestAttributionTokenWithCompletionHandler_(attribution_completion_handler)\n\nif __name__ == \"__main__\":\n    # Call the request function directly\n    request_token()\n    # For asynchronous operations (like network requests with callbacks),\n    # a run loop is often needed to process the callback.\n    # AppHelper.runEventLoop() keeps Python running until stopEventLoop() is called.\n    AppHelper.runEventLoop()","lang":"python","description":"This example demonstrates how to request an attribution token using Apple's AdServices framework via PyObjC. It defines a completion handler to process the token or any errors, and uses `PyObjCTools.AppHelper.runEventLoop()` to manage the asynchronous callback."},"warnings":[{"fix":"Upgrade to Python 3.10 or later for PyObjC v12.0+.","message":"PyObjC dropped support for Python 3.9 with the release of v12.0 and Python 3.8 with v11.0. Ensure your Python environment meets the `requires_python` specification.","severity":"breaking","affected_versions":">=11.0, >=12.0"},{"fix":"Review code interacting with Objective-C initializers, especially those involving manual reference counting or complex object graphs, to ensure correct memory management.","message":"Behavior of initializer methods (those in the 'init' family) changed in v11.1 to align with clang's documentation for Automatic Reference Counting (ARC). PyObjC now correctly models that these methods steal a reference to self and return a new reference.","severity":"breaking","affected_versions":">=11.1"},{"fix":"Refer to Apple's documentation on `AdServices` (e.g., `AAAttribution` on developer.apple.com) and the general PyObjC documentation for bridging rules.","message":"PyObjC bindings do not include documentation. Users must consult Apple's official Developer Documentation for details on framework APIs (e.g., AdServices.AAAttribution classes and methods) and then apply PyObjC's bridging rules.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid using `__init__` for PyObjC-wrapped classes that rely on PyObjC's default `__new__` implementation. If a custom `__new__` is defined, ensure `__init__` behavior is tested across PyObjC versions.","message":"In PyObjC 10.3, support for calling `__init__` when a user-defined `__new__` exists was removed, but partially reintroduced in 10.3.1. However, classes relying on PyObjC's default `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":">=10.3"},{"fix":"Replace Python lists/dicts with their `Foundation` mutable counterparts (`NSMutableArray`, `NSMutableDictionary`) when these collections are observed via KVO.","message":"When observing instance variables (Key-Value Observing - KVO), use `NSMutableArray` or `NSMutableDictionary` instances instead of Python lists or dicts for mutable collections. PyObjC automatically emits KVO notifications for Objective-C classes, but not for pure Python objects.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}