drexqq

[Flutter] permission_handler (android/iOS) 본문

Mobile/Flutter

[Flutter] permission_handler (android/iOS)

drexqq 2023. 1. 4. 23:57
728x90
반응형

geolocator를 사용하던 중 사용자가 권한을 거절하였을 경우 다시 요청을 하거나 설정창으로 유도하고 추가적으로 다른 권한들을 요청을 할 수도 있을 경우를 대비하여서 permission_handler를 사용해보도록 하겠습니다 !

 

뭔가 package들이 하나 둘 씩 증식하고 있지만 괜찮습니다. 괜찮을거에요.

 

https://pub.dev/packages/permission_handler

 

permission_handler | Flutter Package

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.

pub.dev

여기서 확인할 수 있습니다 ~

 

1. package 설치

flutter pub add permission_handler

또는

dependencies:
  ...
  permission_handler: ^10.2.0

pubspec.yaml 파일에 위 처럼 작성하신 뒤 pub get 하시면 됩니다.

 

2. Android 설정

1. android/gradle.properties 파일을 열어서 아래와 같은 설정이 되어 있는지 확인해준 뒤 없으면 추가해줍니다.

...
android.useAndroidX=true
android.enableJetifier=true

2. android/app/build.gradle 파일

...
android {
  compileSdkVersion 33

  ...
}
...

위와 같이 android 블럭에 compileSdkVersion을 수정해줍니다.
(android/build.gradle이 아닌 android/app/build.gradle파일입니다.)

 

3. android/app/src/main/AndroidManifest.xml 파일

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="...">
    ...
    </application>
    <!-- Permissions -->
    ...
</manifest>

manifest 태그 사이에 필요한 권한들을 추가해줍니다 !

 

https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/example/android/app/src/main/AndroidManifest.xml

 

GitHub - Baseflow/flutter-permission-handler: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. - GitHub - Baseflow/flutter-permission-handler: Permission plugin for Flutt...

github.com

모든 권한들은 여기 나와있습니다 !

 

3. iOS 설정

1. Podfile파일

...
post_install do |installer|
  installer.pods_project.targets.each do |target|
    ... # Here are some configurations automatically generated by flutter

    # Start of the permission_handler configuration
    target.build_configurations.each do |config|

      # You can enable the permissions needed here. For example to enable camera
      # permission, just remove the `#` character in front so it looks like this:
      #
      # ## dart: PermissionGroup.camera
      # 'PERMISSION_CAMERA=1'
      #
      #  Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler_apple/ios/Classes/PermissionHandlerEnums.h
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.calendar
        # 'PERMISSION_EVENTS=1',

        ## dart: PermissionGroup.reminders
        # 'PERMISSION_REMINDERS=1',

        ## dart: PermissionGroup.contacts
        # 'PERMISSION_CONTACTS=1',

        ## dart: PermissionGroup.camera
        # 'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.microphone
        # 'PERMISSION_MICROPHONE=1',

        ## dart: PermissionGroup.speech
        # 'PERMISSION_SPEECH_RECOGNIZER=1',

        ## dart: PermissionGroup.photos
        # 'PERMISSION_PHOTOS=1',

        ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        # 'PERMISSION_LOCATION=1',

        ## dart: PermissionGroup.notification
        # 'PERMISSION_NOTIFICATIONS=1',

        ## dart: PermissionGroup.mediaLibrary
        # 'PERMISSION_MEDIA_LIBRARY=1',

        ## dart: PermissionGroup.sensors
        # 'PERMISSION_SENSORS=1',   

        ## dart: PermissionGroup.bluetooth
        # 'PERMISSION_BLUETOOTH=1',

        ## dart: PermissionGroup.appTrackingTransparency
        # 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

        ## dart: PermissionGroup.criticalAlerts
        # 'PERMISSION_CRITICAL_ALERTS=1'
      ]

    end 
    # End of the permission_handler configuration
  end
end

Podfile 파일에 필요한 권한들을 주석해제 해주시면 됩니다!~

 

2. ios/Runner/Info.plist파일

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
	<dict>
    ...
    <!-- Permissions -->

Info.plist파일에 필요한 권한들을 추가해주시면 됩니다 !

 

https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/example/ios/Runner/Info.plist

 

GitHub - Baseflow/flutter-permission-handler: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android

Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. - GitHub - Baseflow/flutter-permission-handler: Permission plugin for Flutt...

github.com

ios권한들은 여기 나와있습니다 !

 

그럼 끘 !

728x90
반응형

'Mobile > Flutter' 카테고리의 다른 글

[Flutter] flutter_boilerplate  (0) 2023.01.10
[Flutter] geolocator (android/iOS)  (0) 2023.01.03
[Flutter] 폰트 적용하기  (0) 2022.12.30
[Flutter] side project (2)  (0) 2022.12.29
[Flutter] side project (1)  (0) 2022.12.28
Comments