2

Spring Mobile 允许 Spring MVC 应用程序检测 Web 客户端是台式机/笔记本电脑、平板电脑还是移动设备。

是否可以使用 Spring Mobile 确定设备是否为 Android/iOS?是否有扩展点,或者它会是“自制”功能吗?

4

2 回答 2

3

Spring Mobile 不包含用于区分 Android 和 iOS 的内置支持。但是,它包括两个接口,DeviceDeviceResolver. 您可以实现这些的自定义版本,以检测 Android 和 iOS 设备并提供其他方法,例如isAndroid()isIOS()。然后你可以配置DeviceResolverHandlerInterceptor使用你的DeviceResolver实现。当您在 a 中使用检测到的设备时,Controller您可以简单地将其转换为您的实现。查看提供的LiteDeviceLiteDeviceResolver实现的灵感。

于 2013-07-20T03:51:28.313 回答
1

我知道这张票已经很老了,但我只是想告诉你,更新版本的 spring-mobile-device 是可能的。

在最新的 1.1.5.RELEASE 中,您可以轻松访问设备的 DevicePlatform。见https://github.com/spring-projects/spring-mobile/blob/1.1.5.RELEASE/spring-mobile-device/src/main/java/org/springframework/mobile/device/DevicePlatform.java

因此,如果您使用 1.1.5.RELEASE,您可以轻松地执行以下操作:

if (currentDevice.isNormal()) {
  // do stuff for desktop devices
} elseif (currentDevice.getDevicePlattform() == DevicePlatform.IOS) {
  // do iOS specific stuff
} else {
  // treat as mobile device
}
于 2018-07-04T16:34:50.113 回答