System.device will not compile

Hi…

I have an old iOS app that I am updating… including a battery check… but the line:

System.Device.BatteryMonitoringEnabled = True

… will not compile with a “This item does not exist” error…

I have tried xojo 2021 r2.1 and 2022r1.

I have tried exporting the project and reimporting.

I am using Jason King’s iOSKit… Could there be some conflict?

Any other ideas are appreciated.

Can you post all of the code in the function with this error? It seems likely that something on a line before or after this one is the actual cause of the error

Jason…

I am pretty sure this is a API 2.0 issue… The entire project was written well before 2.0. I thought I could just access System.Device… but it will not compile with Simple References turned on. So I am in 2.0 hell. If I turn off Simple References then I can use System.Device but then I get over a 100 other errors I have to deal with.

I am considering other options right now.

Ah. Did you download the latest version of iOSKit and replace the version in your project with that? That should resolve any iOSKit related API2 errors.

Jason… The problem is unrelated to IOSKit… I just send in a bare bones project that demonstrates the problem.

I’m not at my Mac right now so can’t try it, but does Global.System.Device work?

Hi Paul…

No that does not work.

To recreate the problem you have to start with an old iOS project… probably one created using a pre-API 2 version of Xojo…

When you open that project with a newer version of Xojo (probably one that supports API 2) on the Build Settings → Shared settings you will see the option “Simple References”. If that is turned on the System.Device. will not compile… But if you turn off “Simple References” then it will compile.

If the project was created with a newer version of Xojo there is no “Simple References” option.

For this old project turning “Simple References” off creates over a hundred other errors… which I can fix… but it was easier in my case to use declares to get the System.Device values I needed.

This code seems to compile in an older iOS project with Simple References turned on:

Var device As Global.System.DeviceData = Global.System.Device
device.BatteryMonitoringEnabled = True

@Paul_Lefebvre, I’m just wondering if a new API 2.0 iOS Mobile Project could be a bug, looking at the following screenshot. But maybe it has to do with the fact that the BatteryState = Unknown (0).

Yes, Paul that does compile… although the first line does not autocomplete.

Simple References is gone for good in API 2. Because Xojo used the same names for things in the namespaced vs non-namespaced things, the compiler couldn’t tell the difference between Folderitem and Xojo.IO.folderitem when your code looked like this:

Dim f as FolderItem

Yes Greg… Simple References are gone… but if you have a project that was created before API 2 then the option is still there and it causes problems with at least System.Device…

Right. It’s a transition crutch but won’t get you a working project in API 2 iOS.