Sencha parses JSON in iphone simulator, but not on iPhone - phonegap - iphone

I have the following code in a Sencha Touch App that parses a JSON response from the server.The app is wrapped around Phonegap and being deployed as a native app on the iPhone. This code works fine on the iPhone Simulator but not on the iPhone itself.
There's a similar question already roaming around SO, unanswered: json not loading in iphone device while using sencha touch and phonegap
Ext.Ajax.request({
url: makeurl, //'http://hostname/index.php?id=1234&action=STARTLIST&cmd=0',
scope : this,
success: function(response){
GoRemote.views.devicelist.setLoading(false);
GoRemote.serverstatus="Ok";
Ext.getCmp('serverstatuspanel').update('Server Status : Okay');
this.listData = Ext.decode(response.responseText);
console.log(response);
if (this.listData.listresponse) {
GoRemote.stores.RoomDeviceListStore.loadData(this.listData.listresponse.listdata, false);
GoRemote.views.toolbar.setTitle(this.listData.listresponse.listinfo.listname);
if(this.listData.listresponse.listinfo.container){
Ext.getCmp('btnBack').setVisible(true);
}
else{
Ext.getCmp('btnBack').setVisible(false);
}
}
else if(this.listData.listcontrol){
if(this.listData.listcontrol.controlinfo.name=="NIAVDevice"){
Ext.getCmp('navigation').setActiveItem(0);
}
}
},
failure:function(response){
GoRemote.serverstatus="Unable to reach director";
Ext.getCmp('serverstatuspanel').update('Server Status : Unable to reach director');
GoRemote.views.devicelist.setLoading(false);
}
// timeout:20000
});
Any help will be much appreciated.

So, we managed to fix the error... The server was a custom built and in the Response Headers was responding with HTTP/1.0 where we needed to have HTTP/1.1
Little thing, big impact.
Thanks!

Related

HTTP Get Requests (Wordpress website Rest API calls) not working in iOS App (Ionic4 and angular)

My Ionic4 App (with angular) is published in both PlayStore (Android) and App Store (iOS). The app is expected to show the latest articles from a Wordpress based website. The app makes a HTTP GET request to fetch JSON data (calling the WordPress rest API at URL https://website.com/wp-json/wp/v2/posts). Sample code from page ts file:
import { HttpClient} from '#angular/common/http';
this.http.get(url).pipe(map(res => {return res}));
My app is working fine in Android but failing to display content in iOS devices.
Apple Support team is unable to help as they only look into swift code. For Ionic code, they are suggesting to get help from Ionic community experts. This issue has blocked our release and became a show stopper for us. I request you to help us resolve this issue at the earliest.
Regards,
Nanda Kishore
I have also faced the same issue in which iOS device fails to make HTTP calls but android works fine.
First I've detected the platform using Platform helper class whether the platform is iOS or not and then tried the same call with adding user-agent while making http call.
callWithUserAgent(url: string) {
const config = {
headers: {
"user-agent": "Mozilla/4.0 (compatible; MSIE 6.0; " + "Windows NT 5.2; .NET CLR 1.0.3705;)"
}
}
return this.httpClient.get(this.baseUrl + url, config);
}
This worked for me.
Adding user-agent sounds crazy but you can try atleast. Make sure you add user-agent in small caps.

canShareVia invokes the success callback when it should not - iOS 11.2

Description
When the Facebook app is not installed, canShareVia method should invoke the error callback, which is working perfectly with my iPhone5s running iOS 10.
When I test it on iPhone5s running iOS 11.2, it is always invoking the success callback in both the cases where the Facebook app is installed and Not installed.
App
A Cordova mobile app
Plugin: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
Device information
iPhone 5s
iOS 11.2
Facebook app: Not installed
Sample code
window.plugins.socialsharing.canShareVia('com.apple.social.facebook', 'msg', null, null, null,
function(success) {
do some stuff....
}, function(error) {
alert(error);
});
Please let me know if any work around has been found.
Updated
Found the cause:
This plugin always returns true since iOS11. So we might need another way to detect if there is an app installed and available.
Get it to work with cordova-plugin-appavailability.
You can implement this way (Appavailability plugin to check Facebook app availability and social sharing plugin to do the actual sharing).
appAvailability.check(
'fb://',
function() { // Success callback
window.plugins.socialsharing.shareViaFacebook(...)
},
function() { // Error callback
console.log('Facebook App is not available');
}
);
Though this is a work around but not a fix, this is the only way for now until the fix gets merged to cordova-plugin-x-socialsharing.
You can find the answer for your question here.
App Availability.
Read this and your requirement will be piece of cake.

blank error message on errThrown-ajax call

$.ajax({
url: loginPath,
password: Password,
username: Username,
type: "GET",
error: function(xhr,textStatus,thrownError)
{
alert(textStatus+" "+thrownError);
},
success: function(data)
{
alert(data);
}
});
I am developing an application in Phonegap for iphone & android, my application needs to call web services at a point, now when i call the web service as above, the alert(textStatus+" "+thrownError); show only "error" the thrownError parameter is blank, all this happens when i run the application on the device/simulator, if i run my code on safari it works just fine without any error, but on the device it somehow screws up. Can some1 tell me what i'm doing wrong? or is there any problem with the web services.
P.S: when i say device i mean iPhone 3GS, as of now i am testing it on this device.
Try alert(xhr.statusText); in the error function.

iPhone browser: Checking if iPhone app is installed from browser

I have web page where I have Button that either opens app (if it installed) or directs to App store if app isn't installed.
It all works if App is installed (I call into "MYAPP://"). However, if app is not installed Safari shows error message "Can not open URL" and that's it. Is there way to disable that message from JScript or is there another way to find out from JScript if app installed (instead of hitting app URL)?
To MODERATOR: I saw someone asked similar question and Moderator wrongly marked it as duplicate. Please understand that question was specifically about doing it from Browser.
Found somewhat suitable solution here
BTW if someone interested in how to do same thing for Android, here is code. We are using Dojo library:
dojo.io.iframe.send({
url: "yourApp://foo/bar",
load: function(resp) {
// nothing to do since it will automagically open App
},
error: function () {
window.location = "go to Android market";
}
});
At Branch we use a form of the code below--note that the iframe works on more browsers. Simply substitute in your app's URI and your App Store link. By the way, using the iframe silences the error if they don't have the app installed. It's great!
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
window.onload = function() {
// Deep link to your app goes here
document.getElementById("l").src = "my_app://";
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
}, 500);
};
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
</body>
</html>
If others have better solutions to detect whether the URI scheme call actually failed, please post! I haven't seen one, and I've spent a ton of time looking. All existing solutions just rely on the user still being on the page and the setTimeout firing.
here is a code that works on iOs, even if the "Can not open URL" still show.
window.location = "yourApp://foo/bar";
clickedAt = +new Date;
setTimeout(function() {
if (+new Date - clickedAt < 2000) {
window.location = "go to Android market";
}
}, 500);
Thanks for the android solution.
I've combined a few things and used the following code to check if it's an iOS device before using the try/catch method from chazbot. Unfortunately, the device still throws a pop-up box to the user saying the address is invalid...anyone know if this is expected behavior for trying to open an invalid URL within a "try" block?
var i = 0,
iOS = false,
iDevice = ['iPad', 'iPhone', 'iPod'];
for ( ; i < iDevice.length ; i++ ) {
if( navigator.platform === iDevice[i] ){ iOS = true; break; }
}
try {
//run code that normally breaks the script or throws error
if (iOS) { window.location = "myApp://open";}
}
catch(e) {
//do nothing
}
There are a few things you can do to improve on other answers. Since iOS 9, a link can be opened in a UIWebView or in a SFSafariViewController. You might want to handle them differently.
The SFSafariViewController shares cookies across apps, and with the built in Safari. So in your app you can make a request through a SFSafariViewController that will set a cookie that says "my app was installed". For instance you open your website asking your server to set such cookie. Then anytime you get a request from a SFSafariViewController you can check for that cookie and redirect to MYAPP:// if you find it, or to the app store if you don't. No need to open a webpage and do a javascript redirection, you can do a 301 from your server. Apps like Messages or Safari share those cookies.
The UIWebView is very tricky since it is totally sandboxed and shared no cookies with anything else. So you'll have to fallback to what has been described in other answers:
window.onload = function() {
var iframe = document.createElement("iframe");
var uri = 'MYAPP://';
var interval = setInterval(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
}, 500);
iframe.onload = function() {
clearInterval(interval);
iframe.parentNode.removeChild(iframe);
window.location.href = uri;
};
iframe.src = uri;
iframe.setAttribute("style", "display:none;");
document.body.appendChild(iframe);
};
I've found it annoying that this will prompt the user if they want to leave the current app (to go to your app) even when your app is not installed. (empirically that seems only true from a UIWebView, if you do that from the normal Safari for instance that wont happen) but that's all we got!
You can differentiate the UIWebView from the SFSafariViewController from your server since they have different user agent header: the SFSafariViewController contains Safari while the UIWebView doesn't. For instance:
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E269
-> UIWebView
Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E269 Safari/602.1
-> SFSafariViewController
Other considerations:
in the first approach, you might want to handle uninstalls: if the user uninstalls your app, you still have a cookie that says that the app is there but it's not, so you might end up with the "Can not open URL" message. I've handled it by removing the cookie after a few tries that didn't end up opening the app (which I know because at every app open I'm resetting this failed tries cookie)
In the second case, it's unclear if you're better off using a setInterval or setTimeout. The issue with the timeout is that if it triggers while a prompt is on, it will be ignored. For instance if you open the link from Messenger, the os will ask you "Leave Messenger? You're about to open another app" when the iframe tries to load your app. If you don't respond either way within the 500ms of the timeout, the redirection in the timeout will be ignored.
Finally even though the UIWebView is sandboxed, you can give it a cookie to identify it, pass it in your deeplink, and save this id as corresponding to device with your app in your server when your app opens. Next time, if you see such a cookie in the request coming from the UIWebView, you can check if it matches a known device with the app and redirect directly with a 301 as before.
I think you can still use the app url as a test. Try wrapping it in a try...catch block,
try {
//run code that normally breaks the script or throws error
}
catch(e) {
//do nothing
}

Ajax call to check if native iPhone application exists on the device?

For our iPhone native application we have a URL : example://
On the iPhone if I type this URL (example://) in safari it automatically opens up my application.
From my "regular" website I have a link which when the user clicks it opens the application. The problem is that if the application is not installed on the iPhone it throws "Unable to open" error.
So before rendering the link on my "regular" site I need to check if the app is installed, one solution is to make an Ajax call and check for status code:
$.ajax({
type: 'POST',
url: 'example://',
complete: function (transport) {
if (transport.status == 200) {
alert('Success');
} else {
alert(transport.status);
alert('Failed');
}
}
});
But this code is always returning a status code "0".
Is there a way to find out from the web if the native iPhone app is installed?
If u are referring to Mobile Safari, you're out of luck. There's no documented public API that I know of that can do this. Mobile Safari is sandboxed away from the OS.
If it's in a webview within an app, u can request the URL and let the webview delegate talk to the native app / query the handling of example://. Otherwise, no way the browser can know existence of any installed app.