Flutter-geolocator: iOSμ—μ„œ 승인 ν›„ 였λ₯˜ : PlatformException (PERMISSION_DENIED, μœ„μΉ˜ 데이터에 λŒ€ν•œ μ•‘μ„ΈμŠ€κ°€ κ±°λΆ€ 됨, null)

에 λ§Œλ“  2019λ…„ 04μ›” 30일  Β·  12μ½”λ©˜νŠΈ  Β·  좜처: Baseflow/flutter-geolocator

πŸ› 버그 λ³΄κ³ μ„œ

  1. μ½”λ“œλŠ” μœ„μΉ˜λ₯Ό μš”μ²­ν•˜κ³  μ‚¬μš©μžλŠ” μŠΉμΈν•˜λ©° μ½”λ“œλŠ” 였λ₯˜λ₯Ό λ°œμƒμ‹œν‚΅λ‹ˆλ‹€.
    PlatformException (PERMISSION_DENIED, μœ„μΉ˜ 데이터에 λŒ€ν•œ μ•‘μ„ΈμŠ€κ°€ κ±°λΆ€ 됨, null)

  2. κ·ΈλŸ¬λ‚˜ 두 번째둜 μœ„μΉ˜λ₯Ό μš”μ²­ν•˜λ©΄ λŒ€ν™” λ‚˜ 였λ₯˜μ—†μ΄ μ˜¬λ°”λ₯Έ μœ„μΉ˜κ°€ μ¦‰μ‹œ λ°˜ν™˜λ©λ‹ˆλ‹€.

μ˜ˆμƒλ˜λŠ” 행동

μœ„μΉ˜κ°€ λ°˜ν™˜λ˜κ³  μœ„μΉ˜λ₯Ό μš”μ²­ν•˜κ³  μ‚¬μš©μžκ°€ 승인 ν•  λ•Œ 였λ₯˜κ°€ λ°œμƒν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

볡제 단계

import 'package:geolocator/geolocator.dart';
try{
   position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
catch(error)
{
  print("error in geolocation: $error"); //error in geolocation: PlatformException(PERMISSION_DENIED, Access to location data denied, null)
  print("position: $position"); // position: null
  print("retrying");  // retrying
  try{
    position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  }
  catch(error)
  {
    await printGeoStatus(5);
    print("2nd error in geolocation $error");
  }
  print("final position: $position"); //flutter: final position: Lat: 59.xyz, Long: 17.xyz

}

ꡬ성

Flutter 버전 : "Channel dev, v1.5.8"
Geolocator 버전 : ^ 4.0.2

ν”Œλž«νΌ:

  • [x] : iphone : iOS
  • [] : λ‘œλ΄‡ : Android
ios triage bug

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

ν˜„μž¬μ΄ λ¬Έμ œμ— λŒ€ν•œ μˆ˜μ • μž‘μ—…κ³Ό λ‹€λ₯Έ 문제 λͺ©λ‘μ„ μž‘μ—… μ€‘μž…λ‹ˆλ‹€ (μžμ„Έν•œ λ‚΄μš©μ€ # 430 μ°Έμ‘°). κ·Έλž˜λ„ μ£Όμš” μ—…λ°μ΄νŠΈκ°€ 될 κ²ƒμž…λ‹ˆλ‹€.

ν˜„μž¬ iOS 츑이 μ€€λΉ„λ˜μ—ˆμœΌλ©° 이제 Android μΈ‘μ—μ„œ μž‘λ™ν•©λ‹ˆλ‹€.

λͺ¨λ“  12 λŒ“κΈ€

@FlashJonasλŠ” μ΅œκ·Όμ— geolocator ν”ŒλŸ¬κ·ΈμΈ (버전 5.0.0)을 μ™„μ „νžˆ λ¦¬νŒ©ν† λ§ν–ˆμœΌλ©° μ΅œμ‹  버전 μ—μ„œλ„μ΄ λ¬Έμ œκ°€ 계속 λ°œμƒν•˜λŠ”μ§€ κΆκΈˆν•©λ‹ˆλ‹€.

@mvanbeusekom 5.0.0μ—μ„œ λ¬Έμ œκ°€ μ—¬μ „νžˆ 쑴재 함을 ν™•μΈν•©λ‹ˆλ‹€.
방금 AppBrewery 과정을 톡해 νŒ¨ν‚€μ§€λ₯Ό λ°œκ²¬ν–ˆμŠ΅λ‹ˆλ‹€.

νŒ¨ν‚€μ§€ λ¬Έμ„œλ₯Ό λ”°λ₯΄κΈ°λ‘œ κ²°μ •ν•˜κ³  plist νŒŒμΌμ— 3 개의 ν‚€λ₯Ό μΆ”κ°€ν–ˆμŠ΅λ‹ˆλ‹€.

<key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to location when open.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to location when in the background.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>This app needs access to location when open and in the background.</string>

첫 번째 μ „ν™”

Position position = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

μ‚¬μš©μžμ—κ²Œ κΆŒν•œμ„ μš”μ²­ν•©λ‹ˆλ‹€ (3 가지 선택 사항 포함) :
image

"앱을 μ‚¬μš©ν•˜λŠ” λ™μ•ˆμ— 만"을 λˆ„λ₯΄λ©΄ 터미널에 λ‹€μŒμ΄ κΈ°λ‘λ©λ‹ˆλ‹€.

[VERBOSE-2 : ui_dart_state.cc (148)] μ²˜λ¦¬λ˜μ§€ μ•Šμ€ μ˜ˆμ™Έ : PlatformException (PERMISSION_DENIED, μœ„μΉ˜ 데이터에 λŒ€ν•œ μ•‘μ„ΈμŠ€κ°€ κ±°λΆ€ 됨, null)

0 Geolocator._handleInvalidPermissions (νŒ¨ν‚€μ§€ : geolocator / geolocator.dart : 191 : 7)

1 Geolocator.getCurrentPosition (νŒ¨ν‚€μ§€ : geolocator / geolocator.dart : 102 : 7)

2 _LoadingScreenState.getLocation (νŒ¨ν‚€μ§€ : clima / screens / loading_screen.dart : 13 : 10)

3 _LoadingScreenState.build.(νŒ¨ν‚€μ§€ : clima / screens / loading_screen.dart : 23 : 13)

4 _InkResponseState._handleTap (νŒ¨ν‚€μ§€ : flutter / src / material / ink_well.dart : 511 : 14)

5 _InkResponseState.build.(νŒ¨ν‚€μ§€ : flutter / src / material / ink_well.dart : 566 : 30)

6 GestureRecognizer.invokeCallback (νŒ¨ν‚€μ§€ : flutter / src / gestures / recognizer.dart : 166 : 24)

7 TapGestureRecognizer._checkUp (νŒ¨ν‚€μ§€ : flutter / src / gestures / tap.dart : 240 : 9)

8 TapGestureRecognizer.handlePrimaryPointer (νŒ¨ν‚€μ§€ : flutter / src / gestures / tap.dart : 177 : 9)

9 <…>

두 번째 λˆ„λ¦„μ€ 정상이며 μœ„μΉ˜λŠ” λ¬Έμ œμ—†μ΄ κΈ°λ‘λ©λ‹ˆλ‹€.

ν”ŒλŸ¬ν„° : μœ„λ„ : 37.785834, λ‘± : -122.406417

μ½”λ“œ :
image

geolocator 5.1.2λ₯Ό μ‚¬μš©ν•˜μ—¬ iPhone 5s, 12.2μ—μ„œ μ—¬μ „νžˆ λ™μΌν•œ λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€.
* νŽΈμ§‘ (Flutter Channel dev, v1.8.4)

// Called after closing welcome alert
Future getFirstLocation() async {
    Position position;
    try {
      position = await Geolocator()
          .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    } catch (error) {
      print("getfirstlocation error 1");
      try {
        position = await Geolocator()
            .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
      } catch (error) {
        print("error in geolocation $error");
      }
    }

    print("getfirstlocation position: $position");

    if (position != null) {
     // send to database
    }
  }

μœ„ μ½”λ“œλ₯Ό μ‹€ν–‰ ν•œ 둜그 :
flutter: getfirstlocation error 1
flutter: getfirstlocation position: Lat: 59.xxxx, Long: 17.yyyy

λ™μΌν•œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.
Android (Oneplus 2)-Android 8.1.0-Geolocator 5.1.2
(μœ„μΉ˜ ν—ˆκ°€κ°€ 뢀여됨)

2019-08-15 16:54:22.606 926-1110/system_process E/InputDispatcher: channel '569829a de.paschke.coffeebreak/de.paschke.coffeebreak.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-08-15 16:54:56.808 14735-14766/? E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(PERMISSION_DENIED, Access to location data denied, null)
    #0      Geolocator._handleInvalidPermissions (package:geolocator/geolocator.dart:207:7)
    #1      Geolocator.getLastKnownPosition (package:geolocator/geolocator.dart:146:7)
    <asynchronous suspension>
    #2      LocationService.getLastKnownLocation (package:coffee_break/services/location_service.dart:24:51)
    <asynchronous suspension>
    #3      UserStoreBase.checkLastLocation (package:coffee_break/stores/user_store.dart:125:36)

μ„Έ 가지 κΆŒν•œ λ¬Έμžμ—΄μ„ λͺ¨λ‘ μ‚¬μš©ν•  λ•Œ λ™μΌν•œ 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€. NSLocationWhenInUseUsageDescription 만 μ‚¬μš©ν•˜λ©΄ 앱이 λ‹€μ‹œ μž‘λ™ν•©λ‹ˆλ‹€. λ‚΄ κ°€μž₯ 쒋은 좔츑은 μ„Έ 가지 κΆŒν•œμ„ λͺ¨λ‘ μ‚¬μš©ν•  λ•Œ 앱이 μ‹œμž‘λ˜κ³  μ‚¬μš©μžμ—κ²Œ 확인을 μš”μ²­ν•˜κΈ° 전에 μœ„μΉ˜λ₯Ό λ¬»λŠ” κ²ƒμž…λ‹ˆλ‹€. UI λ™μž‘μ€ 그것을 ν™•μΈν•˜λŠ” κ²ƒμ²˜λŸΌ λ³΄μ΄μ§€λ§Œ μΆ”μΈ‘ μΌλΏμž…λ‹ˆλ‹€. μ–΄μ¨Œλ“  NSLocationWhenInUseUsageDescription만으둜 μ‚΄ 수 μžˆλ‹€λ©΄ λ‹€λ₯Έ 두 개λ₯Ό μ œκ±°ν•˜μ‹­μ‹œμ˜€.

같은 문제 :( flutter의 λ§ˆμ§€λ§‰ 버전 μ•ˆμ • μ±„λ„μ—μ„œ.

이 νŒ¨ν‚€μ§€λŠ” μ§œμ¦λ‚˜ ...

λ™μΌν•œ 였λ₯˜, Android 10μ—μ„œ κ°€μž₯ μ΅œμ‹  λ²„μ „μ˜ flutter.

λ‚˜λŠ” 같은 λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€!

이 λ¬Έμ œκ°€ ν•΄κ²° 될지 κΆκΈˆν•©λ‹ˆλ‹€. 1 년이 λ„˜μ—ˆκ³  μ‚¬λžŒλ“€μ€ μ—¬μ „νžˆ β€‹β€‹μ§λ©΄ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. μ΅œκ·Όμ— μ €λŠ” Flutterλ₯Ό 배우기 μ‹œμž‘ν–ˆκ³  μ •ν™•νžˆ λ™μΌν•œ 단계λ₯Ό μž¬ν˜„ν•˜λŠ” λ™μΌν•œ 문제λ₯Ό λ°œκ²¬ν–ˆμŠ΅λ‹ˆλ‹€.

iOS ν”„λ‘¬ν”„νŠΈμ—μ„œ "Only while using the app"μ˜΅μ…˜μ„ μ„ νƒν•˜λ©΄ 두 번째둜 μ•±μ—μ„œ μœ„μΉ˜λ₯Ό μš”μ²­ν•΄λ„ μ˜¬λ°”λ₯Έ μœ„μΉ˜ 데이터λ₯Ό μ–»μ—ˆλ”λΌλ„ Flutter μ½˜μ†”μ—μ„œ μ˜ˆμ™Έκ°€ λ°œμƒν•©λ‹ˆλ‹€.

μ΅œμ‹  5.3.2+2 버전을 μ‚¬μš©ν•˜λŠ” PS

ν˜„μž¬μ΄ λ¬Έμ œμ— λŒ€ν•œ μˆ˜μ • μž‘μ—…κ³Ό λ‹€λ₯Έ 문제 λͺ©λ‘μ„ μž‘μ—… μ€‘μž…λ‹ˆλ‹€ (μžμ„Έν•œ λ‚΄μš©μ€ # 430 μ°Έμ‘°). κ·Έλž˜λ„ μ£Όμš” μ—…λ°μ΄νŠΈκ°€ 될 κ²ƒμž…λ‹ˆλ‹€.

ν˜„μž¬ iOS 츑이 μ€€λΉ„λ˜μ—ˆμœΌλ©° 이제 Android μΈ‘μ—μ„œ μž‘λ™ν•©λ‹ˆλ‹€.

버전 6.0.0μ—μ„œ μˆ˜μ •λ˜μ–΄μ•Όν•©λ‹ˆλ‹€.

νšŒμ‹ ν•˜κΈ° λŠ¦μ—ˆμ„ μˆ˜λ„ μžˆμ§€λ§Œ 앱이 iOSμ—μ„œ κΆŒν•œμ„ μš”μ²­ν•˜μ§€ μ•Šκ³  Androidμ—μ„œ μ™„λ²½ν•˜κ²Œ μž‘λ™ν•˜λŠ” λ™μΌν•œ λ¬Έμ œμ— μ§λ©΄ν–ˆμŠ΅λ‹ˆλ‹€.

κΆŒν•œμ„ μš”μ²­ν•˜μ§€ μ•Šμ•˜κΈ° λ•Œλ¬Έμ— κΆŒν•œ μ½”λ“œκ°€ iOSμ—μ„œ μž‘λ™ν•˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. μˆ˜λ™μœΌλ‘œ κΆŒν•œμ„ μš”μ²­ν•˜λŠ” 데 μ‚¬μš©ν•  μˆ˜μžˆλŠ” "location_permissions"λΌλŠ” νŒ¨ν‚€μ§€λ₯Ό μ°Ύμ•˜μŠ΅λ‹ˆλ‹€.

μˆ˜ν–‰ ν•  λ‹¨κ³„λŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  1. "pubspec.yaml"에이 쒅속성 "location_permissions : 3.0.0 + 1"을 μΆ”κ°€ν•©λ‹ˆλ‹€. flutter 1.22.0μ—μ„œ κ·Έλ ‡κ²Œ ν–ˆμœΌλ―€λ‘œ flutter 2.0μ—μ„œλŠ” 이것이 λ¬Έμ œκ°€ 될 수 μžˆμŠ΅λ‹ˆλ‹€.
  2. νŒŒμΌμ—μ„œ νŒ¨ν‚€μ§€ κ°€μ Έ 였기

    import ' package : location_permissions / location_permissions.dart ';

  3. κΆŒν•œμ„ μš”μ²­ν•˜λ €λŠ” νŽ˜μ΄μ§€μ— λ‹€μŒ μ½”λ“œλ₯Ό μΆ”κ°€ν•˜μ‹­μ‹œμ˜€. (μ•±μ˜ 첫 νŽ˜μ΄μ§€μ— μΆ”κ°€ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.)

     <strong i="16">@override</strong>
      void initState() {
       ....
      if (Platform.isIOS) {
        location_permission();
      }
      ....
    

    }

  4. λ™μΌν•œ νŒŒμΌμ— λ‹€μŒ 두 가지 방법을 μΆ”κ°€ν•˜μ‹­μ‹œμ˜€.

    void location_permission () async {
    μ΅œμ’… PermissionStatus κΆŒν•œ = λŒ€κΈ° _getLocationPermission ();
    if (κΆŒν•œ == PermissionStatus.granted) {
    μ΅œμ’… μœ„μΉ˜ = await geolocator.getCurrentPosition (
    desiredAccuracy : LocationAccuracy.best);

      // Use the position to do whatever...
    }
    

    }

    미래_getLocationPermission () async {
    μ΅œμ’… PermissionStatus κΆŒν•œ = await LocationPermissions ()
    .checkPermissionStatus (레벨 : LocationPermissionLevel.location);

    if (permission != PermissionStatus.granted) {
      final PermissionStatus permissionStatus = await LocationPermissions()
          .requestPermissions(
              permissionLevel: LocationPermissionLevel.location);
    
      return permissionStatus;
    } else {
      return permission;
    }
    

    }

이제 iOS 앱에 μœ„μΉ˜ κΆŒν•œμ„ μš”μ²­ν•˜λŠ” νŒμ—…μ΄ ν‘œμ‹œλ©λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰