Ionic: A bit Strange CORS issue with the IOS emulator - ios

This is the code.
$http({ method: 'GET', url: imageUrl });
I'm using the Ionic framework. It works fine in web, andorid mobile and android emulator.
But when I use the same in the IOS 9.3 emulator(4.1.1), I get the error XMLHttpRequest cannot load 'imageUrl'. Origin 'XXX' is not allowed by Access-Control-Allow-Origin.
I suppose I can eliminate any possible errors in the backend, as it is working with the other UI frameworks. Also in the backend(Django framework) I've set CORS_ORIGIN_ALLOW_ALL and CORS_ALLOW_CREDENTIALS to True, added the IP address with port to CORS_ORIGIN_WHITELIST and the needed headers(including Access-Control-Allow-Origin) in CORS_ALLOW_HEADERS.
So, Is there anything specific that needs to be done to make this error go away for the IOS emulator / platform ?

When you run:
ionic cordova emulate ios -l -c -s
Which my guess is, is what you're doing, the emulator is started and is binding to your Mac's IP address instead of 'localhost'. This causes your receiving endpoint to see your Mac's IP in the request header of your get request and because this is a different address than the simulator has it will view your request as a Cross Domain Request.
Please try the following guide from the Ionic team:
Handling CORS issues in Ionic
In short:
Set a proxy in your ionic.config.json file:
{
"name": "proxy-example",
"app_id": "",
"proxies": [
{
"path": "/api",
"proxyUrl": "http://cors.api.com/api"
}
]
}
Point your request to localhost with the port that your live reloading server is using. You can set this in your emulate command like this:
ionic cordova emulate ios -l -c -s --port 8080

CORS issue is something that should be handled at the server. If you are using Azure to deploy your Web Api And Azure Database service then,
1. Open Dashboard.
2. Open your Web API app service.
3. Select CORS which is under API header from menu.
4. Make allow origins to *
Reference Image
And also don't forget to allow all IP's[0.0.0.0 to 255.255.255.255] in the firewall setting in your Azure SQL server
Reference Image 2

Related

How to connect expo react-native app on iOS device to Homestead VM?

I am using Laravel Homestead as a backend VM and expo to build a mobile app with react native.
I am able to make requests in the iOS Xcode simulator to http://mysite.test and I am able to make requests on an actual iOS device to http(s)://mysite.org production server.
However, I am unable to make requests from my physical iOS device to the test environment.
What I need to do:
Allow requests to HTTP.
Expo does not expose the info.plist, but I added this to the app.json file (not sure if it is correct)
"ios": {
"supportsTablet": true,
"infoPlist": {
"NSAppTransportSecurity": {
"NSAllowsArbitraryLoads": true
}
}
}
I am not sure where to send the requests. Posting to http://mysite.test times out, and I have tried many port configurations such as homesteads 192.168.10.10:80, :8000, :8080 etc.
I have also tried pointing to my local machine. The ipv4 is available from networking panel, and my local internet IP address, but no luck. I am lost.
Can someone help me, and others- please??

Intern 3.4.1 on IOS Safari "unable to set accept insecure certs on Safari"

I am trying to Run intern Scripts on IOS Safari I am doing automation for some internal company services...
On MAC Safari same automation worked after placing certificates (with name of server it directly worked by placing certificate , but when i changed server name with ip I again accepted the warning for accept insecure cert) ..
My assumption was same will work for IOS simulator running on Same machine ...
I tired to access (server on which web service is running with both name and ip but didn't work )
I tried by placing "acceptInsecureCerts" : True but I think it's only for firefox
You can install certificates in the simulator using the mobile: installCertificate Appium script. Using it with Intern should look something like this:
const cert = fs.readFileSync('certificate.cer');
const content = cert.toString('base64');
return this.remote.execute('mobile: installCertificate', [{ content }]);

React native - Where is the Dev Settings in IOS? How to change the server host?

I need to change the debug server host in IOS, but not found the Dev Menu in IOS.
You Can Check GitHub Issue : https://github.com/facebook/react-native/issues/1429
Once port get Change you Can start just like react-native start --port=8088

How to set in meteor --mobile-server when using nginx

I have on digitalocean my meteor application running but when I try and test on my iphone the app I am not able to see the login screen.
I don't think it's version dependent and I therefore do not list them. I am happy to provide all the config files if this helps but want to make sure that I am not missing anything conceptually.
My setup is that on my digitalocean (not real URL: https://ABC123.com) server I run the meteor app and the app works fine at the URL. The meteor application has been deployed a while back and is a different release from what I am testing now locally. Source code is quite similar though and it never worked on the iphone. nginx is used to forward the URL domain to
proxy_pass http://127.0.0.1:3100;
Here is the issue now:
I run from my local mac:
meteor run ios-device --mobile-server https://ABC123.com
and run from xcode on the simulator or my iphone and get the attached screenshot. You can see that there is no login prompt which I believe is caused that I do not connect to the server on digitalocean.
It's a also surprising that with the command meteor runs on localhost:3000 as well. But it's probably not the issue.
The way it should look is the below which is taken from the web page:
Thanks already in advance for any responses.
This is resolved. Using Safari as a debugger I noticed that the connection to the server failed due to a non AC SSL certificate. So, after I fixed the SSL certificates it does connect now.

Phonegap developer app error

I am developing an app using phonegap and their developer app to help me along the way. However, I cannot connect to the server after running the command
cordova serve
from the root directory. It serves it up on port 8000 (by default) and I set a static IP address on my macbook to be 10.0.0.129. So when I enter 10.0.0.129:8000 into the "Server Address" field in the developer app I get 'Error!' followed by 'Timeout!'
Could someone please provide an explanation of this and how to fix it?
Many thanks!
I think you need to create a .cordova directory in your project directory, then use phonegap serve, because cordova serve doesn't work with the app.

Resources