ios_permission 0.0.1
ios_permission: ^0.0.1 copied to clipboard
Reliable native iOS camera and microphone permission handling for Flutter, calling AVFoundation directly instead of going through permission_handler.
iOS Permission Plugin #
A Flutter plugin that provides reliable, native iOS camera and microphone permission handling that bypasses unreliable permission_handler plugins. It uses direct platform APIs for maximum reliability and comprehensive permission status information.
Features #
- ✅ Native iOS camera permission handling via
AVCaptureDevice - ✅ Native iOS microphone permission handling via
AVAudioApplication(iOS 17+) with anAVAudioSessionfallback - ✅ Comprehensive permission status information including device metadata
- ✅ Multiple permission request strategies for maximum reliability
- ✅ Smart permission handling with automatic fallback strategies
- ✅ Debug logging via
debugPrintfor troubleshooting - ✅ Testing functions to verify permission system functionality
Why This Plugin? #
The popular permission_handler plugin can be unreliable on iOS, especially for camera and microphone permissions. This plugin solves that by:
- Direct Native API Calls: Uses
AVCaptureDevice.requestAccess()andAVAudioApplication.requestRecordPermission()directly (falling back toAVAudioSessionbelow iOS 17) - Comprehensive Status Information: Returns detailed permission status with device info, timestamps, and actionable flags
- Multiple Request Strategies: Includes fallback methods like audio recording triggers for stubborn permission dialogs
- iOS-Focused: Designed specifically for iOS reliability (Android support can be added later)
Requirements #
- iOS 13.0 or later
- Flutter 3.3.0 or later
Both Swift Package Manager and CocoaPods are supported; no extra setup is needed for either.
Installation #
flutter pub add ios_permission
Or add it to your pubspec.yaml directly:
dependencies:
ios_permission: ^0.0.1
Usage #
Camera Permissions #
import 'package:ios_permission/ios_permission.dart';
// Get detailed camera permission status
final cameraStatus = await IosPermission.getCameraPermissionStatus();
print('Camera status: ${cameraStatus.status.rawValue}');
print('Can use camera: ${cameraStatus.canUseCamera}');
print('Can request: ${cameraStatus.canRequest}');
print('Needs settings: ${cameraStatus.needsSettings}');
// Smart camera permission request (recommended)
final granted = await IosPermission.smartCameraPermissionRequest();
if (granted) {
// Camera permission granted, proceed with camera initialization
} else {
// Handle permission denied
}
// Simple permission request
final result = await IosPermission.requestCameraPermission();
// Quick status check
final canUse = await IosPermission.canUseCameraNow();
Microphone Permissions #
// Get detailed microphone permission status
final micStatus = await IosPermission.getMicrophonePermissionStatus();
print('Microphone status: ${micStatus.status.rawValue}');
print('Can use microphone: ${micStatus.canUseMicrophone}');
// Smart microphone permission request (recommended)
final granted = await IosPermission.smartMicrophonePermissionRequest();
// Standard permission request
final result = await IosPermission.requestMicrophonePermission();
// Force trigger permission dialog (for stubborn cases)
final triggered = await IosPermission.triggerMicrophonePermissionDialog();
// Quick status check
final canUse = await IosPermission.canUseMicrophoneNow();
Testing and Debugging #
// Run comprehensive camera permission test
await IosPermission.testCameraPermission();
// Run comprehensive microphone permission test
await IosPermission.testMicrophonePermission();
Permission Status Information #
The plugin provides detailed status information:
Camera Permission Status #
notDetermined: User hasn't been asked yetauthorized: Permission granteddenied: Permission denied by userrestricted: Restricted by device policyunknown: Error or unknown state
Microphone Permission Status #
undetermined: User hasn't been asked yetgranted: Permission granteddenied: Permission denied by userunknown: Error or unknown state
Each status includes:
canUse*: Whether the permission is granted right nowcanRequest: Whether permission dialog can be shownneedsSettings: Whether user must go to Settings to grant permissiondescription: Human-readable descriptionrawValue: Native platform raw valuetimestamp: When status was retrieveddeviceModel: Device model informationsystemVersion: iOS version
Platform Support #
- ✅ iOS: Full native support
- ❌ Android: Not implemented (returns error status)
- ❌ Web/Desktop: Not supported
iOS Setup #
Add these permissions to your ios/Runner/Info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs camera access to take photos and videos.</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access to record audio.</string>
Example App #
Run the example app to see the plugin in action:
cd example
flutter run
The example app demonstrates:
- Permission status checking
- Permission requesting
- Smart permission handling
- Comprehensive testing
- Real-time status updates
Troubleshooting #
- Missing
Info.plistkeys: iOS terminates the app on a permission request ifNSCameraUsageDescription/NSMicrophoneUsageDescriptionare absent. See iOS Setup. - Permission dialog not showing: Try the
triggerMicrophonePermissionDialog()method for microphone permissions - Status not updating: Use the refresh functionality in the example app
- Unexpected behavior: Enable debug logging and check console output
- Testing: Use the built-in test functions to verify functionality
Contributing #
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License #
MIT — see LICENSE for details.