搜尋套件、儲存庫與 APP 分類

套件詳情v2.3.2

detect_fake_location

一個用於檢測位置是否被模擬或偽造的 Flutter 插件

AndroidiOS
近 30 天下載
2700
喜歡數
41
Pub 分數
140

安裝套件

flutter pub add detect_fake_location

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 插件,用於檢測裝置的位置是否被模擬或偽造。它利用 Android 和 iOS 的平台特定 API 來分析位置資料,以識別欺騙跡象,例如不一致的 GPS 訊號或異常移動模式。這有助於應用程式驗證使用者位置的真實性,從而提升位置敏感型應用的安全性和可靠性。該插件輕量且可無縫整合到現有的 Flutter 專案中。

適用情境

  • 驗證共乘應用中的使用者位置
  • 防止基於地理位置的服務中的詐欺行為
  • 確保健身追蹤應用的準確性
  • 保護對地理位置限制內容的存取
  • 檢測虛假簽到或位置分享

主要特色

  • Android 與 iOS 的跨平台支援
  • 使用原生設備 API 進行精確檢測
  • 輕量且易於整合
  • 提供位置偽造的明確指示
  • 最小性能開銷

適合對象

  • 需要安全位置驗證的應用程式
  • 開發位置感知服務的開發者
  • 具有反詐欺要求的應用程式
  • 使用即時地理定位的行動應用程式
  • 需要符合位置完整性標準的項目

使用建議

  • 需要適當的位置存取權限
  • 可能無法偵測所有進階偽造方法
  • 行為可能在不同裝置間略有差異
  • 不是伺服器端驗證的替代品
  • 在已越獄/越獄裝置上的效果有限

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

detect_fake_location

This is a Flutter plugin that detects if the user is using a fake(mock or simulated) location on their device.

Pub License GitHub code size in bytes

Installation

To use this plugin, add detect_fake_location as a dependency in your pubspec.yaml file.

Permissions

iOS

Add the following entries to your Info.plist file

<key>NSLocationAlwaysUsageDescription</key>
<string>App needs access to location when in the background.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App requires access to location when open.</string>

Add the following to your Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    # Start of the permission_handler configuration
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
      # dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        'PERMISSION_LOCATION=1'
    ]
    end
  end
end
Android

Add the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission to your Android Manifest.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Usage

Import the package with:

import 'package:detect_fake_location/detect_fake_location.dart';

Then you can use the following method to check if the user is using a fake location:

// Basic usage (default behavior)
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation();

// Advanced usage with configuration options
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation(
  ignoreExternalAccessory: true, // Ignore external accessories like CarPlay
);

Configuration Options

ignoreExternalAccessory (iOS only)

By default, the plugin detects fake locations from both software simulation and external accessories. However, external accessories like CarPlay, external GPS devices, or other legitimate hardware can trigger false positives.

  • Default: false (maintains backward compatibility)
  • When to use true: If you want to ignore location data from external accessories and only detect software-based fake locations
  • Use case: Prevent false positives when users have legitimate external accessories connected
// Only detect software-simulated locations, ignore external accessories
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation(
  ignoreExternalAccessory: true,
);

Example

import 'package:flutter/material.dart';
import 'package:detect_fake_location/detect_fake_location.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My App'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              child: Text('Detect Fake Location (Standard)'),
              onPressed: () async {
                bool isFakeLocation =
                    await DetectFakeLocation().detectFakeLocation();
                _showResult(context, isFakeLocation, 'Standard Mode');
              },
            ),
            SizedBox(height: 20),
            ElevatedButton(
              child: Text('Detect Fake Location (Ignore External Accessory)'),
              onPressed: () async {
                bool isFakeLocation = await DetectFakeLocation()
                    .detectFakeLocation(ignoreExternalAccessory: true);
                _showResult(context, isFakeLocation, 'Ignore External Accessory Mode');
              },
            ),
          ],
        ),
      ),
    );
  }

  void _showResult(BuildContext context, bool isFakeLocation, String mode) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Fake Location Detection Result'),
          content: Text(
              'Mode: $mode\nThe user is${isFakeLocation ? '' : ' not'} using a fake location.'),
          actions: <Widget>[
            TextButton(
              child: Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
}

Image 1 Image 2

Limitations

For iOS, the plugin uses the CLLocationSourceInformation class to detect if the location is simulated by software or produced by an external accessory. This class is only available on iOS 15 or later.

Contribute

Contributions are welcome! Please submit issues and pull requests on the GitHub repository.

Credits

For requesting permissions: permission_handler

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。