I am working on an application which needs access to the local network implemented by simple xmlHttp calls. In App Preview the app is working fine on iOS and Android but not on Windows.
Is this because the App Preview app itsself does not have LAN access allowed in the manifest or is there way I can obtain local network access also within the App Preview on Windows Phone 10?
Once the app will be ready, will it be sufficient to allow "privateNetworkClientServer" under "Add Permissions" in the Windows build settings? Is there any special format or will I just write the parameter as is? (https://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx)
I recommend you try a built app on your Windows 10 device to test your theory. Off-hand I do not know what permissions are set in the App Preview manifest, won't be able to answer that question until after the holiday break, requires input from engineering.
It has costed me some time but I have finally found a solution to the problem.
The reason is indeed the mssing privateNetworkClientServer-permission which does not allow the Windows app to communicate in any way with the local network. I have tried with XMLHttpRequest, Ajax and Cordova libs but nothing to...
Adding the permission in the "Add Permissions" box iin the build settings does not help neither. This applies to the blank permission as well as to the full mainfest file format. Is there some other format you can suggest?
Anyway, be writing the following plugin, network access works fine at least for build versions:
<?xml version="1.0" encoding="UTF-8"?> <plugin id="bv.cordova.winnwcs" version="1.0.0"> <name>Windows Add privateNetworkClientServer Capability</name> <description>Add privateNetworkClientServer Capability to appxmanifest</description> <!-- windows8 --> <platform name="windows8"> <config-file target="package.appxmanifest" parent="/Package/Capabilities"> <Capability Name="privateNetworkClientServer" /> </config-file> </platform> <!-- windows --> <platform name="windows"> <config-file target="package.appxmanifest" parent="/Package/Capabilities"> <Capability Name="privateNetworkClientServer" /> </config-file> </platform> </plugin>
This is taken from post http://stackoverflow.com/questions/31415230/cordova-manifest-capability-for-windows-platform, just adding "windows" for UAP builds.
Now XMLHttpRequest in the local network is working fine for build versions but not for testing. Is there any way you could add a similar policy to one of the next versions of App Preview? Especially with you new focus on IOT, in fact the purpose of my app is to discover and setup such devices in the local network, it would be really helpful if not essential being able to test communication already during development.
Peter -- quick update. We looked into what it would take to add this feature to App Preview and found that by doing so it would prevent us from being able to publish App Preview in the Microsoft store (according to the Microsoft Cordova experts). So, unfortunately, this is not something we can add to the Windows version of App Preview, due to that onerous restriction. Thus, the only way to test that feature is to build an app and install it directly on your device, as you have done.
Thank you for the feedback on this. I am a bit surprised as we have other HTML5 based apps - I admit not done with XDK yet - using this permission and there has been no problem with store approval at all. Also the app we are currently developing on XDK does not report any problems running the store compliance test locally. However, once we will be ready to release the first version, I will let you know if it passes store approval. At the end, as long as the users grants the permissions during installation, I do not see any reason why an app should be prohibited to communicate in the local network.
You were absolutely right, you are not supposed to set privateNetworkClientServer anymore for Windows 10 apps. What I have written in my previous post will only work for Windows 8 (if one needs to publish on the store). BUT there is a a new command which is allowed and works the same way:
<platform name="windows"> <preference name="WindowsDefaultUriPrefix" value="ms-appx://" /> </platform>
This will change the default context of the app from web (default is ms-appx-web) to local. Once set, both local and web access will work as long as you do not touch the whitelists. Reference: https://github.com/apache/cordova-windows/blob/master/cordova-windows10.md
So getting back to the initial question: is there any way to make local network access work in App Preview as well?