Adobe Air Can't Connect to Server on iOS10 - actionscript-3

I have an application on Appstore like 2 years.
I developed with Adobe AIR.
On iOS10 my app not working. Can't connect to http links.
I debug and get error from connections:
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: http://api.website.net/check.php
I used HTTPStatusEvent.HTTP_STATUS for understand any solution, it gives 0
Any methods to solve?
MY CODE:
var urlReq:URLRequest = new URLRequest ("http://api.website.net/check.php");
urlReq.method = URLRequestMethod.POST;
var urlVars:URLVariables = new URLVariables();
urlVars.user_id = Main.instance.userID;
urlReq.data = urlVars;
var loader:URLLoader = new URLLoader (urlReq);
loader.addEventListener(Event.COMPLETE, onCreditComplete);
loader.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpStatusHandler);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(urlReq);

Sounds like it's related to the iOS App Transport security settings.
To enable http requests you will need to either define the domains as exceptions in your application descriptor:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>api.website.net</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
or add a global ignore security setting:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
These settings should be added to the InfoAdditions node in your iPhone settings of your application descriptor:
<iPhone>
<InfoAdditions><![CDATA[
<key>UIDeviceFamily</key>
<array>
<string>1</string>
<string>2</string>
</array>
<!-- Add the above settings here -->
]]></InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
<Entitlements>
<![CDATA[
]]>
</Entitlements>
</iPhone>

Related

Problem with authentication from actionscript to siteminder SSO

I am migrating an adobe flex application from web version (running in flash player) to adobe air desktop application.
My application communicate with a "blazeDS service" via remote object (a way pair adobe flex with java backend) at URL: http://myhost.example.com/mycontext/messagebroker/amf
The above URL is protected with CA site minder, if user has not logged in, the system redirect to siteminder log in page at: http://myhost.example.com/sso/*...
I tried send post request to siteMinder service via post man to login success.(Post user name, password, pin, etc..) Then siteminder responsed with the cookies.
My task is try to send http request via action script to login from my air application.
I wrote a simple air application send request when initialize as bellow:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import flash.net.*;
function init(){
var req : URLRequest= new URLRequest("http://myhost.example.com/sso/");//The Siteminder service URL.
var formData : URLVariables = new URLVariables("email=test&uname=1002102571&pass=test&gender=male"); //Post data
req.data = formData;
req.contentType = "application/x-www-form-urlencoded";
req.method = "POST";
var urlLoader : URLLoader = new URLLoader(req);
urlLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onResponse);
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(req);
}
function onResponse(event){
Alert.show("aaa" + event.target);
}
function onComplete(event){
Alert.show("bbb");
}
function response(event){
Alert.show("รข0");
}
function fault(event){
Alert.show("nb");
}
]]>
</mx:Script>
</mx:WindowedApplication>
Then siteminder response cookies too.
But when I intergrate my code to the real system, site minder respond log in fail. I don't know what is differrent between two application. Please share your advice.

iOS open link with maps apps

I'm working on an event app and I'm trying to add a "Get directions" button that opens up directions in either Apple Maps or Google Maps. I'm happy to use Apple maps for now because it's easy to embed with http://maps.apple.com/?q=XYZ().
My app is displaying an HTML website with a UIWebView, so this may be the problem, but when you press the link it actually opens within the UIWebView and displays Google Maps randomly but accurately. Is there a function I can put into my HTML code that forces the link to open in the native Apple or Google Maps?
COMPLETE ANSWER
CODE:
- (IBAction)getDirectionsAction:(id)sender {
NSURL *googleURL = [[NSURL alloc]
initWithString:[NSString stringWithFormat:#"comgooglemaps://?daddr=%#", #"44.294349,-70.326973"]];
NSURL *googleWebURL =
[[NSURL alloc] initWithString:[NSString stringWithFormat:#"http://www.maps.google.com/maps?daddr=%#",
#"44.294349,-70.326973"]];
NSURL *appleURL = [NSURL URLWithString:#"http://maps.apple.com/?daddr=311+East+Buckfield+Road+Buckfield+Maine"];
NSURL *wazeURL = [NSURL URLWithString:#"waze://?ll=44.294349,-70.326973&navigate=yes"];
// Lets try the Waze app first, cuz we like that one the most
if ([[UIApplication sharedApplication] canOpenURL:wazeURL]) {
[[UIApplication sharedApplication] openURL:wazeURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// Lets try the Apple Maps app second
if ([[UIApplication sharedApplication] canOpenURL:appleURL]) {
[[UIApplication sharedApplication] openURL:appleURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// If Apple Maps is unsuccessful, let's try the Google Maps app
if ([[UIApplication sharedApplication] canOpenURL:googleURL]) {
[[UIApplication sharedApplication] openURL:googleURL
options:#{}
completionHandler:^(BOOL success){
}];
return;
}
// Uh, oh...Well, then lets launch it from the web then.
else {
[[UIApplication sharedApplication] openURL:googleWebURL
options:#{}
completionHandler:^(BOOL success){
}];
}
}
PLIST PROPERTIES:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>http://maps.apple.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>http://maps.google.com/</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
</dict>
</dict>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
<string>comgooglemaps</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>For Use for directions</string>
BUTTON
1X
2X
3X
Instead of using the http protocol in your URL, try using the maps protocol instead, so that your link looks something like:
maps://maps.apple.com/?q=Test+Search
You can also open it in Google Maps, if the user has it installed, by using a URL such as:
comgooglemaps://?q=Test+Search
Though you might get unexpected results if the user doesn't have it installed.
If this doesn't work, it's possible to use the UIWebView delegate method webView:shouldStartLoadWithRequest:navigationType: to intercept links and open the Maps application properly.
Here you can find info on the Google Maps URL Scheme
UIApplication.sharedApplication().openURL(NSURL(string:
"comgooglemaps://?q=XYZ")!)
Will enforce Google Maps to be used.
You might want to do
UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!)
first, to ensure that Google Maps is available. If not, simply call your regular
http://maps.apple.com/?q=XYZ()
to open apple maps.

iOS share extension in chrome

Just added share extension to my app.
It's working fine in safari.
When launching it from Chrome the "ExtensionPreprocessingJS.js" isn't called.
as a result the following code is not invoked:
MyExtensionJavaScriptClass.prototype = {
run: function(arguments) {
// Pass the baseURI of the webpage to the extension.
arguments.completionFunction({"baseURI": document.baseURI});
},
Please advise.
That behavior is documented as being a Safari option, not something that applies to every web browser.
In Share extensions (on both platforms) and Action extensions (iOS only), you can give users access to web content by asking Safari to run a JavaScript file and return the results to the extension.
[Emphasis mine]
Try to put/replace/add this to your info.plist of extension
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsText</key>
<true/>
<key>NSExtensionActivationSupportsWebPageWithMaxCount</key>
<integer>1</integer>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>DemoPreprocessor</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
No need for that complicated stuff. This works both in Google Chrome and Safari:
override func viewDidLoad() {
super.viewDidLoad()
for item in extensionContext!.inputItems {
if let attachments = item.attachments {
for itemProvider in attachments! {
itemProvider.loadItemForTypeIdentifier("public.url", options: nil, completionHandler: { (object, error) -> Void in
if object != nil {
println(object) //This is your URL
}
})
}
}
}
}

Load External Image in Flex Mobile App

I am trying to load images from my website on my Flex Mobile Application. When I run the code using my localhost, everything works perfectly. However, when I try to load the images from my live website, I get the error:
IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2036: Load Never Completed. URL: http://sortsports.com/images/players/nfl/sketch/8850x300.jpg" errorID=2036]
I am using a Loader to load the image and a LoaderContext setting checkPolicyFile to false.
var lc:LoaderContext = new LoaderContext();
lc.checkPolicyFile = false; // bypass security sandbox / policy file - does this effect quality when scaling? - See more at: http://www.onegiantmedia.com/as3--load-a-remote-image-from-any-url--domain-with-no-stupid-security-sandbox-errors#sthash.ZRnTf99k.dpuf
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, playerImageLoadCompleteHandler);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
trace('loading: ' + remoteFileUrl);
loader.load(new URLRequest(remoteFileUrl), lc); // add a loader context to not check the policy file
private function playerImageLoadCompleteHandler(event:Event):void
{
var loaderInfo:LoaderInfo = event.target as LoaderInfo;
playerImage.source = loaderInfo.content;
}
private function loaderIOErrorHandler(ev:Event):void{
trace("Image not found and ioError: " + ev);
playerImage.source = 'k';
}
I also have a crossdomain policy in the root of the url:
<?xml version="1.0"?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>
I load the crossdomain like this:
Security.loadPolicyFile(Globals.currentDomain + "/crossdomain.xml");
And I try to allowDomain
//Security.allowDomain('http://sortsports.com/');
But I get an error
SecurityError: Error #3207: Application-sandbox content cannot access this feature.
So I put it in the try catch:
try {Security.allowDomain("*");}catch (e) { trace("e.message: " + e.message); };
Again, the code works great on localhost. I don't think using a proxy is a possibility as this is a mobile app.

URLLoader in actionscript 3 not using the same web session on some machines?

var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://domain.net/registerVideo.php");
var vars:URLVariables = new URLVariables();
vars.action = "insert";
vars.record = publishMode;
vars.name = streamName;
request.data = vars;
request.method = URLRequestMethod.POST;
loader.load(request);
The above client side code works for my machine(using the same web session),
but not working for some other machines.
Is this a known bug??
My guess is that you are testing this from the domain.net machine but loading from somewhere else. If it is not working from another machine, you may have a security sandbox violation. Try to add a crossdomain.xml file on your server with something like this to see if that fixes your issue.
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>
I wouldn't advise keeping this for production if it fixes your issue. For more info, see this link.