如何防止 Swift 中假 GPS 应用程序的模拟 GPS 位置(欺骗)?

how to prevent mock GPS location (spoofing) from fake GPS app in Swift?

我正在制作一个使用 CLLocationManager 的应用程序,该应用程序将用于记录员工的出席情况。为了验证员工的出席者,我们将获得 GPS 坐标。

据我所知,有一个应用程序通常用于获取假 GPS。当用户使用我的应用程序时,我想阻止这个模拟 GPS 处于活动状态。

如果我使用 Android,我可以下载假的 GPS 应用程序。当假设我使用 tinder 时,我可以伪造我的位置。假设我实际上在曼谷,但因为我使用假的 GPS 应用程序,我可以将我的火种位置设置在伦敦,而不是曼谷。

所以基本上我想防止用户使用我的应用程序时来自假 GPS 的虚假位置。老实说我真的不知道iOS是否允许假位置

我可以在 Swift 中获得该功能吗?

这是我用来获取坐标的 class LocationManager

import UIKit
import CoreLocation


class LocationManager: NSObject {
    let manager = CLLocationManager()
    var didGetLocation: ((Coordinate?) -> Void)?

    override init() {
        super.init()

        manager.delegate = self
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.requestLocation()
    }

    func getPermission() {
        // to ask permission to the user by showing an alert (the alert message is available on info.plist)

        if CLLocationManager.authorizationStatus() == .notDetermined {
            manager.requestWhenInUseAuthorization()
        }

    }
}




extension LocationManager : CLLocationManagerDelegate {

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        if status == .authorizedWhenInUse {
            manager.requestLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
        print(error.localizedDescription)
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        guard let location = locations.first else {
            didGetLocation?(nil)
            return

        }
        let coordinate = Coordinate(location: location)
        if let didGetLocation = didGetLocation {
            didGetLocation(coordinate)

        }
    }
}

private extension Coordinate {
    init(location: CLLocation) {
        latitude = location.coordinate.latitude
        longitude = location.coordinate.longitude
    }
}

我唯一能告诉你的是你需要有一个备份方法来获取用户位置,我也遇到过类似的情况。使用 IP 位置 API/service(并非 100% 可靠)并在您的应用中创建逻辑来比较数据。

PS:这不是您问题的解决方案,这只是您可以尝试使用的一个想法。但这只有在使用不同的 cities/states 欺骗位置时才最有效,因为 IP 位置不是高精度位置。如果 GPS 说你在圣地亚哥,但你的 IP 说你在旧金山,那么你可以阻止 UI/request 直到用户确认。

PS2:在 iOS 中,我知道用户可以欺骗其位置的唯一方法是 运行 通过 XCode 应用程序,使用位置功能,然后打开你的应用程序。 (过去经常用 pokemon go #notproud :))

您可以查看应用是否越狱。如果它已经越狱,您可以通过显示永久对话框或其他内容来阻止用户使用该应用程序。 如果你想知道如何检测设备是否越狱,你可以自己找到它。有那么多文献会告诉你怎么做。

干杯:)