Repository navigation
feat: (Capacitor 9) access local network Api Level 37 - #8624
fabiomartino wants to merge 4 commits into
Conversation
|
Fabio, I implemented you PR in my dev env and everything seemed to work ok, except when I added the code to check local network permission: I got this error after running 'ionic capacitor sync android --prod': Not sure what that means, but this tweak fixed it: I'll leave it up to you to decide if this is a bug that needs to be fixed, or if using the permState['localNetwork'] syntax is proper. |
The PR introduced an index-signature PermissionResult type, which breaks dot access (TS4111) for consumers compiling with the noPropertyAccessFromIndexSignature option. Declare the localNetwork property explicitly on a dedicated LocalNetworkPermissions interface and drop the open index-signature type from the public API.
Nice catch, and thanks for testing it on device. You don't need to keep the workaround: we already included the proper fix in this PR (commit 1be88f7, "fix(core): return a closed LocalNetworkPermissions type"). The plugin now returns a LocalNetworkPermissions interface with an explicit localNetwork: PermissionState property, so permState.localNetwork compiles under any tsconfig, no brackets needed. |
|
Your latest commit fixed the "Property 'localNetwork' comes from an index signature, so it must be accessed with ['localNetwork']" issue for me. Now the "permState.localNetwork" syntax works fine. Thanks for your help. Any idea how to get one of the maintainers to evaluate your PR and hopefully merge it? |
This comment was marked as abuse.
This comment was marked as abuse.
|
Thanks for the contribution! We are doing investigation into this before committing this PR as an overall solution. |
|
Hi @fabiomartino, thank you for the feature and pull request. We’re going to have to respectfully decline adding this as a core plugin bundled within Capacitor, for a few reasons:
I do think this is excellent ground for a standalone plugin, and I’d love to see your work become a community-maintained plugin. I’d be glad to help open a space for it at https://github.com/capacitor-community. How does that sound? |
|
That's disappointing. I thought Fabio's fix was well thought out. I think it would be a good idea to mention this issue in the Capacitor 9 release notes, otherwise people are going to be scratching their heads when they target SDK 37 and local network access stops working. Fabio, thanks for your help. if you decide to not go the capacitor-community route, I'd be interested to hear your thoughts about implementing a fix outside of Capacitor. |
|
@moose4lord, completely understand. We’ll document this in the Capacitor 9 upgrade guide, including the steps for apps that target SDK 37. I still recommend a standalone plugin for this. This change touches the Bridge’s permission validation and state code, which every plugin that declares permissions relies on, and it special-cases one permission by API level. I’d like to see whether that logic can live in the plugin, or be expressed as a general per-permission rule rather than a hard-coded branch in core. @fabiomartino, thanks again for this work. I’m happy to help in any way I can, whether that’s reviewing a community plugin or talking through an approach. |
Starting in Android 17 (API 37), local-network addresses are blocked by
default for apps targeting SDK 37+, with ACCESS_LOCAL_NETWORK as a runtime
permission. Without framework support, apps using CapacitorHttp against
LAN devices fail with timeouts on API 37+.
This change:
manifest (merged into every app, safely ignored on older SDKs);
string literal + literal API 37 constant so the compile SDK can stay
below 37);
manifest check / DENIED caching on enforced SDKs, in both
Bridge.validatePermissions() and Bridge.getPermissionStates();
checkPermissions()/requestPermissions() flow from JavaScript, with no
app-side native code required;
Bridge permission state/validation behavior, and the LocalNetwork plugin
registration and pre-37 granted flow.
iOS
iOS intentionally ships no native implementation for this plugin: the system
does not expose a runtime permission API for local-network access, so
checkPermissions()/requestPermissions()go through the web fallback andreport
granted. The one-time prompt is driven byNSLocalNetworkUsageDescriptioninInfo.plistthe first time the appcommunicates with a LAN device.
Branch targeting
Targeted at
next(9.x): the ACCESS_LOCAL_NETWORK capability is a newplatform feature tied to API 37+, so the plugin lands in the pre-release
line. The stable 8.5.2 patch line carries the grant-behavior fix separately.
Closes #8613