Skip to main content
tgom
Inspiring
May 8, 2017
Answered

Load Works in Android But Not in iOS

  • May 8, 2017
  • 1 reply
  • 1578 views

When a user opens my app, I send a simple load command to .NET code which sends back the string "WiFi Connected".

I recently published an Android app using AIR 24.0.0.180 in which that load works fine.

Then, using the same fla, I tried to publish an iOS app using AIR 24.0.0.180 for iOS. The ipa was created ok, but the load did not work.

In fact, the load also failed in 26.0.0.93 & 25.0.0.134 AIRs for iOS.

Then I jumped to AIR 18.0.0.144 for iOS and IT WORKED!

I can attempt to upload this to the Apple Store, but I would rather go with a more recent version of AIR for iOS If possible.

Please help! Here's the code:

//NOTE:  Assume a textbox named WiFi_txt is on stage

Var DotNetURL:String = “Location of .NET code”

var scriptRequest:URLRequest = new URLRequest();

var scriptLoader:URLLoader = new URLLoader();

var scriptVars:URLVariables = new URLVariables();

var Action_Type:String = "";   //Needed for success & failure handlers

function database_action(actionType:String) {

                Action_Type = actionType;

                scriptVars = new URLVariables();

                scriptVars.type = "BUTTON";

                scriptVars.ActionType = actionType;

                switch (actionType) {

                                case "CheckWiFi":

                                                scriptVars.Dummy = 999;

                                                break;

                                default:

                                                break;

                }

                scriptRequest = new URLRequest();

                scriptRequest.method = URLRequestMethod.POST;

                scriptRequest.data = scriptVars;

                scriptRequest.url = DotNetURL;

                scriptLoader = new URLLoader();

                scriptLoader.dataFormat = URLLoaderDataFormat.VARIABLES;   //VARIABLES or TEXT

                scriptLoader.addEventListener(Event.COMPLETE, handleSuccess, false, 0, true);

                scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleError, false, 0, true);

                scriptLoader.load(scriptRequest);

}

function handleSuccess(e:Event):void

{

                var variables:URLVariables = e.currentTarget.data as URLVariables;

                switch (Action_Type) {

                                case "CheckWiFi":

                                                if (variables.returnStr == "WiFi Connected") {

WiFi_txt.text = "A WiFi Connection Exists!";

                                                }

                                                break;

                                default:

                                                break;

                }

                preloader.visible = false;

                scriptLoader.removeEventListener(Event.COMPLETE, handleSuccess);

                scriptLoader.removeEventListener(IOErrorEvent.IO_ERROR, handleError);

                scriptLoader = null;

}

function handleError(e:IOErrorEvent):void

{

                scriptLoader.removeEventListener(Event.COMPLETE, handleSuccess);

                scriptLoader.removeEventListener(IOErrorEvent.IO_ERROR, handleError);

                scriptLoader = null;

                switch (Action_Type) {

                                case "CheckWiFi":

WiFi_txt.text = "IOError!";

                                                break;

                                default:

                                                break;

                }

}

WiFi_txt.text = "A WiFi Connection is required!";

database_action("CheckWiFi");

This topic has been closed for replies.
Correct answer yachts9999

Same server returns it fine for the ipa created with 18.0.0.144.


I've just taken your code, made a couple of small changes and created an AIR for iOS app using SDK 25 and successfully published, loaded and ran it on an iPad.

FYI I did this:

1. Changed the first part of your handleSuccess function slightly to:

function handleSuccess(e: Event): void {

  var loader:URLLoader = URLLoader(e.target);

  trace(loader.data);

  var variables: URLVariables = new URLVariables(loader.data);

  trace('variables.returnStr  = ' + variables);

  switch (Action_Type) {

  case "CheckWiFi":

  if (variables.returnStr == "WiFi Connected") {

  WiFi_txt.text = "A WiFi Connection Exists!";

  }

  break;

  default:

  break;

  }

// I don't have a preloader

  //preloader.visible = false;

  scriptLoader.removeEventListener(Event.COMPLETE, handleSuccess);

  scriptLoader.removeEventListener(IOErrorEvent.IO_ERROR, handleError);

  scriptLoader = null;

}

2. I tried  a secure URL to retrieve data from, which worked fine.

3. I tried and insecure URL which also worked fine,  but with this code added into the descriptor xml file

<iPhone>

        <requestedDisplayResolution>high</requestedDisplayResolution>

        <InfoAdditions><![CDATA[

    <key>UIDeviceFamily</key>

    <array><string>2</string></array>

                           <key>NSAppTransportSecurity</key>

                           <dict>

                           <key>NSAllowsArbitraryLoads</key><true/>

                           </dict>

                   ]]></InfoAdditions>

    </iPhone>

4. The server code (PHP) was this:

<?php

echo "returnStr=WiFi Connected";

?>

I can't say exactly if it was just one of these items alone that made it all work and of course I'm using PHP for the server response but I do now have a working version so I'm sure you will get this working too!

1 reply

Inspiring
May 10, 2017

Are you using a secure connection (https) in

Var DotNetURL:String = “Location of .NET code”

If not, you may need to set App transport Security to allow the URL to load. See this article

AIR 20.0.0.233 URLMonitor broken with iOS 9 ?

which has this text:

App Transport Security (ATS) is being introduced from Apple in iOS9, which doesn’t allow unsecure connections between App and Web services. Due to this change all the connections which are made to unsecure web sites via Loader, URLLoader will discontinue and not work due to App Transport Security. Please specify exceptions to the default behavior by adding keys to InfoAdditions tag of application descriptor of your app.

PS Var should be var (lowercase v)

tgom
tgomAuthor
Inspiring
May 10, 2017

Before I try that, can you explain why, on my iPad version 9.3.5, the ipa created with AIR 18 works?

Inspiring
May 10, 2017

I think ATS was only introduced into the AIR SDK at version 20.

From the linked article:

In AIR 20 build 233 we have upgraded iOS9 SDk.