如何在iOS上的Gluon Mobile中使用PositionService?

Tho*_*mas 8 gluon-mobile

我想PositionService在iOS上使用Gluon Mobile.我编写了一个在桌面上运行的小型示例应用程序,提供(按预期)假位置更改,以及在Android上.但是,在iOS模拟器上,不会调用侦听器.以下是代码的相关部分:

public class BasicView extends View {

        private static final Logger LOGGER = Logger.getLogger(BasicView.class.getName());

        final Label label;

        public BasicView(String name) {
            super(name);
            label = new Label();
            VBox controls = new VBox(15.0, label);
            controls.setAlignment(Pos.CENTER);
            setCenter(controls);
            // get current position
            Platform p = PlatformFactory.getPlatform();
            PositionService ps = p.getPositionService();
            outputPos(ps.getPosition());
            ps.positionProperty().addListener((obs, oldPos, newPos) -> {
                LOGGER.log(Level.INFO, "\nobs: {0}\noldPos: {1}\nnewPos: {2}",
                        new Object[]{obs, oldPos, newPos});
                outputPos(newPos);
            });
        }

        private void outputPos(Position p) {
            if (p != null) {
                label.setText(String.format("We are currently here: %f %f",
                        p.getLatitude(),
                        p.getLongitude()));
            }
        }

        @Override
        protected void updateAppBar(AppBar appBar) {
            appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
            appBar.setTitleText("Basic View");
            appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e -> System.out.println("Search")));
        }

    }
Run Code Online (Sandbox Code Playgroud)

我添加了libCharm.a,但据我所知,这里不需要它.

我还发现了如下更新info.plist的提示,但无论有没有,都不会调用监听器.

    <key>UIRequiredDeviceCapabilities</key>
    <array>
            <string>armv7</string>
            <string>location-services</string>
    </array>
    ...
    <key>NSLocationWhenInUseUsageDescription</key>
            <string>Location is required to find out where you are</string>
    <key>NSLocationAlwaysUsageDescription</key>
            <string>Location is required to find out where you are</string>
Run Code Online (Sandbox Code Playgroud)

关于我所看到的位置的唯一输出是:

Aug 27, 2016 1:37:31 PM com.gluonhq.charm.down.ios.IOSPositionService <init>
INFO: Location Manager configured with desiredAccuracy 10.00 and distanceFilter 100.00

Aug 27, 2016 1:37:31 PM com.gluonhq.charm.down.ios.IOSPositionService <init>
INFO: Telling LocationManager to start updating location.
Run Code Online (Sandbox Code Playgroud)

我想我在这里错过了一些东西......一如既往,非常感谢任何帮助.

编辑:对不起,忘了build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.thomaskuenneth.gluon.positionservicedemo.PositionServiceDemo'

dependencies {
    compile 'com.gluonhq:charm:3.0.0'

    androidRuntime 'com.gluonhq:charm-android:3.0.0'
    iosRuntime 'com.gluonhq:charm-ios:3.0.0'
    desktopRuntime 'com.gluonhq:charm-desktop:3.0.0'
}

jfxmobile {
    android {
        manifest = 'src/android/AndroidManifest.xml'
        compileSdkVersion = 23
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.gluonhq.**.*',
                'io.datafx.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 1

我听从了 Jos\xc3\xa9 Pereda 的建议,升级到了 Gluon Mobile 4。在执行以下步骤后,我看到 iPad 模拟器中的位置发生了变化。因此,我建议任何遇到与我在问题中提到的相同困难的人尝试升级。这解决了我的问题。

\n\n

更新 build.gradle 如下:

\n\n
buildscript {\n    repositories {\n        jcenter()\n    }\n    dependencies {\n        classpath \'org.javafxports:jfxmobile-plugin:1.1.1\'\n    }\n}\n\napply plugin: \'org.javafxports.jfxmobile\'\n\nrepositories {\n    jcenter()\n    maven {\n        url \'http://nexus.gluonhq.com/nexus/content/repositories/releases\'\n    }\n}\n\nmainClassName = \'com.thomaskuenneth.gluon.positionservicedemo.PositionServiceDemo\'\n\ndependencies {\n    compile \'com.gluonhq:charm:4.0.1\'\n}\n\njfxmobile {\n    downConfig {\n        version \'3.0.0\'\n        plugins \'display\', \'lifecycle\', \'statusbar\', \'storage\', \'position\'\n    }\n    android {\n        manifest = \'src/android/AndroidManifest.xml\'\n        androidSdk = "/Users/thomas/Library/Android/sdk"\n        compileSdkVersion = 24\n    }\n    ios {\n        infoPList = file(\'src/ios/Default-Info.plist\')\n        forceLinkClasses = [\n                \'com.gluonhq.**.*\',\n                \'io.datafx.**.*\',\n                \'javax.annotations.**.*\',\n                \'javax.inject.**.*\',\n                \'javax.json.**.*\',\n                \'org.glassfish.json.**.*\'\n        ]\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

由于Charm Down API略有变化,将访问位置服务的代码修改如下:

\n\n
package com.thomaskuenneth.gluon.positionservicedemo;\n\nimport com.gluonhq.charm.down.Services;\nimport com.gluonhq.charm.down.plugins.Position;\nimport com.gluonhq.charm.down.plugins.PositionService;\nimport com.gluonhq.charm.glisten.control.AppBar;\nimport com.gluonhq.charm.glisten.mvc.View;\nimport com.gluonhq.charm.glisten.visual.MaterialDesignIcon;\nimport java.util.logging.Level;\nimport java.util.logging.Logger;\nimport javafx.geometry.Pos;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.VBox;\n\npublic class BasicView extends View {\n\n    private static final Logger LOGGER = Logger.getLogger(BasicView.class.getName());\n\n    final Label label;\n\n    public BasicView(String name) {\n        super(name);\n        label = new Label();\n        VBox controls = new VBox(15.0, label);\n        controls.setAlignment(Pos.CENTER);\n        setCenter(controls);\n        Services.get(PositionService.class).ifPresent(serivce -> {\n            serivce.positionProperty().addListener((obs, oldPos, newPos) -> {\n                LOGGER.log(Level.INFO, "\\nobs: {0}\\noldPos: {1}\\nnewPos: {2}",\n                        new Object[]{obs, oldPos, newPos});\n                outputPos(newPos);\n            });\n        });\n    }\n\n    private void outputPos(Position p) {\n        if (p != null) {\n            label.setText(String.format("We are currently here: %f %f",\n                    p.getLatitude(),\n                    p.getLongitude()));\n        }\n    }\n\n    @Override\n    protected void updateAppBar(AppBar appBar) {\n        appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));\n        appBar.setTitleText("Basic View");\n        appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e -> System.out.println("Search")));\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

在早期版本中,似乎有必要将文件 ibCharm.a 放在 src/ios/jniLibs 中。使用 Gluon 4,我在链接时不断看到错误,直到删除该文件。我认为由于 Charm Down 的重构,该目录中不再需要该 lib。

\n\n

另外,请注意,您需要编辑 Default-Info.plist,如有关 PositionService 的 Charm Down 文档中所述。我已经在我的问题中描述了这一点。截至今天,该文档并未提及考虑添加

\n\n
<string>location-services</string>\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
<key>UIRequiredDeviceCapabilities</key>\n<array>\n    ...\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我认为如果您的应用程序需要位置服务并且否则无法运行,这可能是个好主意。也许 iOS 专家可以对此发表评论。

\n