Ionic.platform.device undefined until first view



I’m developing an app in which users can read post stored in a bd via an external control panel (like Wordpress). It is an app with no user auth policy, so I want to store device info using ionic.Platform.device() and save in my db the posts being read by a device.

I got a problem during the first execution. Once you have installed the app and execute it for the first time, I detect the device and check if you ran this app in the past, and show a message like “You have 20 unread posts”. But ionic.Platform.device returns undefined and ionic.Platform.isReady returns false. This detection script is executed at app.js run() for the main info. And I execute this detection in every view change, so if I go to another section in the app, the detection is executed again and then it works. Seems like the app “needs to complete” an initial view process before the device can be detected.