network call fail n OS X app

Greetings,

I am making a call to the following function to check if there is an internet connection :

----------------------------------------------------------------------------- -- checkNetworkConnection ----------------------------------------------------------------------------- networkConnectivity = function () local cnx = socket.connect ('www.google.com', 80) if (cnx == nil) then return false end cnx: close() return true end

This works fine when I build with a development profile. But when I submit to the Apple Store, it does not work.

Likewise, php script are called from the app and they fail.

Are there any particular permissions that should be set in the build.settings?

See: https://coronalabs.com/blog/2015/09/17/about-app-transport-security-ats/

That might fix it.

Rob

Thank you Rob, I set NSAllowsArbitraryLoads to true but this did not solve the problem. 

Any clues?

Here is my build.settings. 

settings = { osx = { plist = { NSAppTransportSecurity = { NSAllowsArbitraryLoads = true, }, }, }, orientation = { default = "landscapeRight", supported = { "landscapeLeft", "landscapeRight", }, }, window = { defaultMode = "normal", enableCloseButton = true, enableMaximizeButton = true, enableMinimizeButton = true, suspendWhenMinimized = true, resizable = true, titleText = { default = "My App" }, }, }

I tried to connect to port 443 (work sur with dev profile) but did not work when built for the Apple Store.

Can someone help on this?

Can someone confirm, this is working in osX apps submitted with an Apple Store provisioning profile.

Should I file a bug ?

Here is our build.settings that work.

Please note the NSExceptionDomains.

We also call PHP on our domain ubj3d.com and the above solved our problem.

 osx = { plist = { NSHumanReadableCopyright = "Copyright 2016 by Damir Kranjcec.", NSAppTransportSecurity = { NSExceptionDomains = { ["ubj3d.com"] = { NSIncludesSubdomains = true, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true }, ["facebook.com"] = { NSIncludesSubdomains = true, NSExceptionRequiresForwardSecrecy = false, NSThirdPartyExceptionAllowsInsecureHTTPLoads = true }, }, }, }, }

Hello, thank you for the reply.

However, when I build with an Apple Production provision profile (with code signing identities) the network calls do not work.

Are you getting any errors in your console log? See https://forums.coronalabs.com/topic/62935-how-to-get-logs-for-macosx/ for how to get to the console log for desktop builds.

Rob

I’m unaware of any issues with OS X and networking. The ATS stuff is really for iOS. I don’t think Apple is forcing ATS on OS X apps (I missed this was an OS X post earlier).

Can you break down your network.request to a simple sample app and try that?

Rob

Here is a sample app that exhibits the problem :

NetworkConnection.zip

When built with an Apple Production provision profile (with code signing identities) network calls does not work.

There are no error messages in the log. The call to the function networkConnectivity returns false.

While this is tangential to your problem, its worth knowing that there are several networking “things” we are working on. We have to get the OpenSSL plugin patched up to the latest version due to security issues Google is flagging. Apple wants IPV6 support sooner than later and so on. We have several moving parts going on address these concerns.

I was expecting today’s Daily Build to have the new socket library in place, but it looks like it’s still yesterday’s build out there. After daily build 2880 and later posts, there should be a new socket library. This may solve your specific issue. Then again, it may not. Before I have you file a bug report on this, I would like to see if it got fixed already.

So watch for 2880 to post (or later) and see if the problem still exists. If it does, then use your sample project and file a bug report using the “Report a bug” link at the top of this page. Make sure to paste the URL of this thread into the bug report’s description field as you describe the issue in detail to the engineers.  Once you submit the bug, you will get an email with a CaseID in the subject, please post that back here as a reference.  Lets see if it gets fixed first though.

Rob

Tried with build 2883 and still not working.

Case 45925 submitted

Any news on this case ?

Its assigned to an engineer. I don’t know where it falls in his priorities to look at however. Can you drop back to 2830 and see if you have the same problem there?

Rob

Still no news on this case …

Anyone here succeeds in making network calls in OS X applications (published in the Mac App Store) ?

When building for distribution the app gets sandboxed, so you need to add the entitlements for network access when doing that.

put this in you build.settings

settings = { osx = { entitlements = { ["com.apple.security.network.client"] = true, }, }, }

Hello everybody.

I have maybe the same problem.

I am playing around with a simple webview app.

I included the ATS things (allow all, or just specific domains) and the recomendation from ojnab in the build settings, but I always get:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

The weird thing is, that on the mac simulator it is working and a build on another machine worked as well. I am not sure about the other machine but it is not working on El Capitan (10.11.5)

Best,

Felix

Did you include the entitlements suggested a post above?
 

Yes.

Whereas it was working without on the other machine…

Just tested it again on the first machine that runs Yosemite (10.10.5) and it works like expected. Am I right in assuming that this is pre ATS?

Dont know if it is important, but the version of xcode installed on this machine (where it works) is 7.2.1.

Best,

Felix