Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Load Works in Android But Not in iOS

Explorer ,
May 08, 2017 May 08, 2017

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");

1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , May 11, 2017 May 11, 2017

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"

...
Translate
Contributor ,
May 10, 2017 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 10, 2017 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 May 10, 2017

I guess the question is:  Why doesn't the build insert the code:

<iPhone>

<InfoAdditions>

                    <![CDATA[

                           <key>NSAppTransportSecurity</key>

                           <dict>

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

                           </dict>

                   ]]>

          </InfoAdditions>

</iPhone>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 10, 2017 May 10, 2017

Possibly because this is just a workaround and at some future time Apple may insist on secure https connections, making this redundant.

Having said that, editing the descriptor xml file is not out of the ordinary. Which IDE are you using BTW?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 May 10, 2017

Flash CS6.

I'm going to try this with 24.0.0.180 . . .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 May 10, 2017

Here's what I did:

(1) Created my ipa with Flash CS6 using AIR 24.0.0.180 for iOS

(2) Edited the xml iPhone tag as follows:

  <iPhone>

    <InfoAdditions>

      <![CDATA[<key>UIDeviceFamily</key><array><string>1</string><string>2</string></array>]]>

      <![CDATA[<key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/></dict>]]>

    </InfoAdditions>

    <requestedDisplayResolution>high</requestedDisplayResolution>

  </iPhone>

(3) Uploaded the ipa to iTunes

(4) Installed it on my iPad

(5) Ran it & again load did not work.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 10, 2017 May 10, 2017

Can you check what other messages you might be getting back from the server? Try some traces in your handleSuccess() function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 May 10, 2017

There is one line of code on the server:

Response.Write("returnStr=" + "WiFi Connected")

and it's not coming back; so, I assume the request is simply not being sent to the server???

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 10, 2017 May 10, 2017

Sounds quite possible. Perhaps you could write a really simple test URLLoader and use the same server to see if anything can be returned.

I don't know .Net but could you get the server to output any error message in it's response?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2017 May 10, 2017

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 11, 2017 May 11, 2017

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2017 May 12, 2017
LATEST

I want to thank yachts9999 for his persistence in solving this problem!

In trying to avoid editing the descriptor and believing that Apple might soon insist on a secure https connection, I made my site https secure. Then I successfully created an AIR for iOS app using SDK 25.0.0.134 and successfully published, loaded and ran it on my iPad.

Now I embark on the journey to upload it to the Apple Store . . .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines