Copy link to clipboard
Copied
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");
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"
...Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
Before I try that, can you explain why, on my iPad version 9.3.5, the ipa created with AIR 18 works?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Flash CS6.
I'm going to try this with 24.0.0.180 . . .
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Can you check what other messages you might be getting back from the server? Try some traces in your handleSuccess() function.
Copy link to clipboard
Copied
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???
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Same server returns it fine for the ipa created with 18.0.0.144.
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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 . . .
Find more inspiration, events, and resources on the new Adobe Community
Explore Now