Feature: Determine the device type from formulas

New properties help you determine if your user is using an iPhone, an Android device, a Windows PC, an iPad or a Mac. Use this feature to do things like only showing a text box if the user is running an iPhone or changing app colors based on the operating system.

The new start screen holds app-wide properties, such as the zoom level and the app language. The zoom level is a so-called calculated property, meaning that you can associate a formula with it and access its value by writing App.ZoomLevel from any formula (provided that you have retained the default name “App” for your start screen).

If you look in the reference sidebar, you’ll notice that there are three additional properties besides the zoom level. These properties are so-called read-only properties, meaning that you can’t associate formulas with them, only access their values from formulas you write.

(It’s worth your while to peruse the reference sidebar in search of properties that you may not have heard of before and which are not part of the inspector. For instance, the InitialValue property, available on all fields, can be associated with a formula determining the initially-displayed value of a field. You can use that property to ensure that date and time fields display today’s date when they are first shown, for instance.)

Without further ado, these are the three new read-only properties:

  • DeviceType. Returns the type of the device running the app or a blank value if the device type is not known. Valid values are “iphone” if the user is running an iPhone, “ipad” if the user is running an iPad and “android” if the user is running an Android device.

  • OperatingSystem. Returns the name of the operating system the user is running or a blank value if the operating system is not known. Valid values are “ios” if the user is running Apple’s iOS operating system (powering iPhones and iPads), “android” if the user is running Google’s Android operating system, “windows” for Microsoft’s Windows operating system, “mac” for Apple’s macOS system and “linux” for systems running the Linux kernel.

  • UserEmailAddress. Returns the email address of your user or a blank value if the user is not signed in. Currently, this property always returns a blank value for shared apps (as they are, at present, always public and don’t require users to sign in). Your own email address is returned if you’re running an app in Calcapp Creator’s preview sidebar or through Calcapp Connect, which isn’t terribly useful. We expect this property to become more useful soon, though.

When is it useful to be able to determine the device type and operating system from a formula? We can think of a number of scenarios:

  • Displaying device-specific hints. Entering decimal numbers or negative numbers on an iPhone is tricky if you don’t know how. (Your user must press * or # to enter a decimal separator or + to type a minus sign.) Lots of apps currently inform users of this using a text box. That’s great for iPhone users, but is only distracting if the user is running any other device like a PC, an iPad or an Android device. You can now associate the formula App.DeviceType = "iphone" with the Visible property of said text box to ensure that only iPhone users see it.

  • Linking to apps in the correct app store. What if you want to recommend your user to install a separate app and you have both Android and iOS users? You’d need to include separate links for the different app stores. You can use the OperatingSystem property to ensure that users only see the link relevant to them.

  • Changing app colors to match the host operating system. Apps built with Calcapp mostly look like iOS apps today, with one notable exception: iOS apps typically don’t have colorful navigation bars. Android apps, however, do often sport colorful navigation bars. What if you want your app to blend in better and have colorful navigation bars on Android but make them iOS-gray otherwise? Simply associate a formula like the following with the BarBackgroundColor property of your first panel: IF(App.OperatingSystem = "ios", FirstPanel.BackdropColor, FirstPanel.PrimaryColor). What this does is that it uses the backdrop color (which is gray unless you’ve changed it) if the user is running iOS and the primary color (which is blue unless you’ve changed it) otherwise.

We’re sure you can come up with lots of other uses for these new properties!

« Feature: Pad numbers with leading zeroes Feature: Calcapp Creator has a new start screen »