Reputation: 2792
i created a class to ask for permission immediately it get to login, it show on Android but on iOs i am not seeing any permission grant.
class PermissionService {
Future permissionHandler() async {
await Permission.contacts.shouldShowRequestRationale;
if (await Permission.contacts.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
}
Map<Permission, PermissionStatus> statuses = await [
Permission.locationWhenInUse,
Permission.locationAlways,
Permission.photos,
Permission.camera,
Permission.location,
Permission.microphone,
Permission.notification,
].request();
if (statuses[Permission.location].isDenied) {
print("Location permission is denied.");
}
if (statuses[Permission.camera].isDenied) {
print("Camera permission is denied.");
}
if (statuses[Permission.photos].isDenied) {
print("Photos permission is denied.");
}
if (statuses[Permission.notification].isDenied) {
print("Notification permission is denied.");
}
if (statuses[Permission.microphone].isDenied) {
print("Microphone permission is denied.");
}
if (statuses[Permission.locationWhenInUse].isDenied) {
print("locationWhenInUse permission is denied.");
}
if (statuses[Permission.locationAlways].isDenied) {
print("locationAlways permission is denied.");
}
}
}
and i call this function in the initstate of the Login.dart
Upvotes: 20
Views: 26798
Reputation: 91
Specifically, in some packages (for example Alarm package), you may need to turn on some features from the Signing and Capabilities section. Keep in mind
Upvotes: 0
Reputation: 4426
In my case, I also use this library. But the problem is not with the library. The app doesn't even show a dialog asking for location permissions. Then I go to settings, go to the app, and I don't see the requested location permission interface.
The problem was with my Info.plist
file.
<key>NSLocationAlwaysUsageDescription</key>
<string>Cho phép Chat truy cập thông tin vị trí để chia sẻ vị trí trong cuộc trò chuyện</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Cho phép Chat truy cập thông tin vị trí để chia sẻ vị trí trong cuộc trò chuyện</string>
Permission NSLocationAlwaysUsageDescription
above NSLocationWhenInUseUsageDescription
is wrong. Therefore, the order should be reversed.
Upvotes: 4
Reputation: 9744
The permission_handler package introduced a breaking change in version 8.0.0
, see changelog. Permissions on iOS are disabled by default, and you have the set the correct GCC_PREPROCESSOR_DEFINITIONS
in you Podfile. An example Podfile can be found here, but basically you have to add this to you Podfile, set the permissions that you don't use to 0
:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
# e.g. when you don't need camera permission, just add 'PERMISSION_CAMERA=0'
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
end
Edit 1: Once that is done, save your Podfile and then stop the current instance of the project since hot restart will not reflect the changes. Rebuild the project and permission_handler
requests should now be working perfectly.
Edit 2: As suggested by @YugankaSharan it might be necessary to run pod install
for the changes to take effect.
Upvotes: 59