Ionic.platform.IOS() doesn't work


#1

Hi,

I’m trying to do a simple platform check in a view, where I would display a different element depending on the platform used.

<a href="{{item.fields.iOSLink}}" onClick="javascript:return openExternal(this)" class="button button-block button-balanced" ng-if="ionic.Platform.isIOS()">Download</a>
<a href="{{item.fields.androidLink}}" onClick="javascript:return openExternal(this)" class="button button-block button-balanced" ng-if="ionic.Platform.isAndroid()">Download</a>
<a href="{{item.fields.wpLink}}" onClick="javascript:return openExternal(this)" class="button button-block button-balanced" ng-if="ionic.Platform.isWindowsPhone()">Download</a>

I have tried setting a variable in the controller or doing the check directly as above, but it doesn’t work (it doesn’t recognize my iPhone - haven’t checked on Android or WP).

What is wrong with this?

Thanks!


#2

Do you use device.platform to find on which platform your app run?


#3

What do you mean?
There is no device.platform method, only a ionic.platform.device(), as far as I can tell from the doc, however I use ionic.Platform.isIOS() to check if the platform is iOS, but it always returns false - even if I am on an actual, very standard iPhone.


#4

ionic’s API uses Apache Cordova which provides device.platform through cordova-plugin-device.
When something does not work as expected, you’d better look at the basic stuff.


#5

Thanks, I didn’t know.
It says “device not defined”, even after reinstalling the plugin and platforms. I do load ng-cordova before cordova.js, and call the device.platform after $ionicPlatform.ready().


#6

Both device.platform and window.device.platform works for me. If you use ngCordova then you could also use $cordovaDevice.getPlatform() but it won’t work either because here it seems to be a plugin initialisation issue.
So I guess you should have an error in Safari’s console when remote debugging your iphone on USB.


#7

Did you follow the ngCordova doc?

Include ng-cordova.js or ng-cordova.min.js in your index.html file before cordova.js and after your AngularJS / Ionic file (since ngCordova depends on AngularJS).

Forget about it, I just read you did.


#8

This afternoon we add same problem and the only thing that worked is the order of scripts and wrapping each plugin call with the deviceready event.

Exactly what the ngCordova doc says.


#9

Yeah, I stopped at “include your scripts in the right order”… Wrapping it in deviceready events did the trick. Thank you!