I am developing Ionic app for mobile app and browser. I need to show login page if desktop browser or mobile browser. I used platform object to identify whether mobile app page or browser. I used “core” or “mobileweb” platform to identify the browser. But Its failed to identify in mobile, tablet and ipad browser. Anyone help me.
can you please provide us some code fragments?
if (this.platform.is('core') || this.platform.is('mobileweb')) {
// Login page
}else{
// Home page
}
this code was deployed and app running in node server. When I access the corresponding IP in mobile browser, It will be redirected to home page. Its not my requirement. Whats wrong with this ?
It somehow thinks you’re using a different user agent I guess. Did you try to check if you’re just nog running on Cordova? So !this.platform.is(‘cordova’) . What happens if you check this.platform when setting a breakpoint when calling the website? Or check you user agent when running it on the mobile browser by inspecting it through the chrome debugger/safari debugger depending on the device.
Where are you calling this code btw?
Platform Name Description
android - on a device running Android.
cordova - on a device running Cordova.
core - on a desktop device.
ios - on a device running iOS.
ipad - on an iPad device.
iphone - on an iPhone device.
mobile - on a mobile device.
mobileweb - in a browser on a mobile device.
phablet - on a phablet device.
tablet - on a tablet device.
windows - on a device running Windows.
if (this.platform.is(‘core’) || this.platform.is(‘mobileweb’)) {
// login page
}else{
// Home page
}
This above conditional block not satisfied in mobile browser. Actually “mobileweb” is the browser on a mobile device. But condition satisfied very rare case, most of the cases not satisfied. Whats wring with this ? How to resolve ? Help please.
I perfectly understand your issue, but could you please answer some of the questions asked? Little bit hard to tell what’s going wrong without some decent answers
Hey sorry luukschoen… I checked in mobile browser with this log. Here I placed that log result…
isPlatform_android : true
isPlatform_ios : false
isPlatform_core : false
isPlatform_cordova : true
isPlatform_ipad : false
isPlatform_iphone : false
isPlatform_mobile : true
isPlatform_mobileweb : false
isPlatform_phablet : false
isPlatform_tablet : false
isPlatform_windows : false
I’m kind off in the dark over here. I don’t know how it’s possible it says that platform cordova is true? Somehow something got screwed up. Did you check the user Agent string of your mobile browser?
Yes when we use all commands of ionic, we have to add cordova keyword also. For example I am going to launch the app in emulator, I have to use the command “ionic cordova emulate android”. what the term “user Agent string” here ? I am not clear about this. i am just used Platform object to know the platform to details.
Okay if that’s what’s adding in Cordova, my bad. But if you build for browser I was in the understanding you should just run npm run ionic:build --prod , nothing to do with cordova what so ever. So, how exactly did you produce this build you’re running on your node server?
Here I explained the steps which I followed before the conversation with you.
To add platform I used this command "ionic cordova platform add browser
To build I used this command "ionic cordova build android"
Then i placed server.js file into this directory platforms->browser->www
Executed “node server” command. It will give the port number which is server running port.
Then using my local ip and port, I can view in the browser.
Here I explained the steps which I followed after I had conversation with you.
To add platform I used this command "ionic cordova platform add browser
To build I used this command "npm run ionic:build --prod"
But nothing changes in any files. What to do ?