패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.6.1

background_location_tracker

안드로이드 및 iOS용 백그라운드 위치 추적을 허용하는 플러터 플러그인

AndroidiOS
30일 다운로드
830
좋아요
76
Pub 점수
150

패키지 설치

flutter pub add background_location_tracker

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

안드로이드 및 iOS 모두에서 백그라운드에서 지속적인 위치 추적을 가능하게 하는 플러터 플러그인입니다. 앱이 사용 중이 아닐 때도 사용자의 위치를 모니터링할 수 있어 피트니스, 내비게이션 또는 물류 애플리케이션에 적합합니다. 플러그인은 플랫폼별 구성 및 권한을 처리하여 다양한 기기에서 신뢰성 있는 작동을 보장합니다. 플러터 생태계와 원활하게 통합되며 최소한의 배터리 영향으로 실시간 업데이트를 지원합니다.

사용 사례

  • 피트니스 트래킹 앱
  • 배송 및 물류 모니터링
  • 지오펜싱 애플리케이션
  • 여행 및 내비게이션 도구
  • 위치 기반 알림

주요 기능

  • 백그라운드 위치 업데이트
  • 크로스 플랫폼 지원 (Android 및 iOS)
  • 낮은 배터리 소모
  • 자동 권한 처리
  • 실시간 위치 스트리밍

적합한 대상

  • 지속적인 위치 추적을 필요로 하는 앱
  • 위치 인식 서비스를 구축하는 개발자
  • 교통 또는 건강 분야의 모바일 애플리케이션

고려 사항

  • 사용자 명시적 허가 필요
  • 기기 배터리 수명에 영향을 줄 수 있습니다
  • 플랫폼별 설정이 필요합니다
  • 개인정보 준수 필요
  • iOS에서의 백그라운드 실행 제한

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

background_location_tracker

A new Flutter plugin that allows you to track the background location for Android & iOS

Build Status Coverage Status pub package

Android Config

Update compile sdk

Compile sdk should be at 29 at least.

android {
  ...
  compileSdkVersion 29
  ...

  defaultConfig {
    ...
    targetSdkVersion 29
    ...
  }
  ...
}

iOS Configuration

Update Info.plist

Add the correct permission descriptions

	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
	<key>NSLocationAlwaysUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>

Add the background location updates in xcode

Or add the info to the Info.plist

	<key>UIBackgroundModes</key>
	<array>
		<string>location</string>
	</array>
Update the AppDelegate
import UIKit
import Flutter
import background_location_tracker

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GeneratedPluginRegistrant.register(with: self)

        // Register plugins for background execution - this method is deprecated 
        // but kept for backward compatibility
        BackgroundLocationTrackerPlugin.setPluginRegistrantCallback { registry in
            GeneratedPluginRegistrant.register(with: registry)
        }

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

Flutter implementation

Make sure you set the @pragma('vm:entry-point') to make sure you can find the callback in release.

@pragma('vm:entry-point')
void backgroundCallback() {
  BackgroundLocationTrackerManager.handleBackgroundUpdated(
    (data) async => Repo().update(data),
  );
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await BackgroundLocationTrackerManager.initialize(
    backgroundCallback,
    config: const BackgroundLocationTrackerConfig(
      loggingEnabled: true,
      androidConfig: AndroidConfig(
        notificationIcon: 'explore',
        trackingInterval: Duration(seconds: 4),
        distanceFilterMeters: null,
      ),
      iOSConfig: IOSConfig(
        activityType: ActivityType.FITNESS,
        distanceFilterMeters: null,
        restartAfterKill: true,
      ),
    ),
  );

  runApp(MyApp());
}

Future startLocationTracking() async {
  await BackgroundLocationTrackerManager.startTracking();
}

Future stopLocationTracking() async {
  await BackgroundLocationTrackerManager.stopTracking();
}

FAQ:

I get a Unhandled Exception: MissingPluginException(No implementation found for method .... on channel ...)
This is mostly caused by a misconfiguration of the plugin:
- Android: This plugin now uses Flutter's Plugin V2 embedding pattern (FlutterPluginBinding) so you don't need to set a manual plugin registrant callback.
- iOS: For compatibility with older Flutter versions, the setPluginRegistrantCallback is still available but will be removed in a future version.

If you're using Flutter 1.12 or later, the plugin should work out of the box with the V2 embedding.

Migration Guide

Upgrading from older versions

This plugin has been updated to use the modern Flutter Plugin V2 embedding pattern with FlutterPluginBinding. If you're using Flutter 1.12 or later, you don't need to make any changes to your app's code.

For backward compatibility, the older methods are still available but marked as deprecated:

  • BackgroundLocationTrackerPlugin.setPluginRegistrantCallback on Android
  • BackgroundLocationTrackerPlugin.setPluginRegistrantCallback on iOS

These methods will be removed in a future version of the plugin.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.