ios_permission 0.0.1 copy "ios_permission: ^0.0.1" to clipboard
ios_permission: ^0.0.1 copied to clipboard

PlatformiOS

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 an AVAudioSession fallback
  • Comprehensive permission status information including device metadata
  • Multiple permission request strategies for maximum reliability
  • Smart permission handling with automatic fallback strategies
  • Debug logging via debugPrint for 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:

  1. Direct Native API Calls: Uses AVCaptureDevice.requestAccess() and AVAudioApplication.requestRecordPermission() directly (falling back to AVAudioSession below iOS 17)
  2. Comprehensive Status Information: Returns detailed permission status with device info, timestamps, and actionable flags
  3. Multiple Request Strategies: Includes fallback methods like audio recording triggers for stubborn permission dialogs
  4. 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 yet
  • authorized: Permission granted
  • denied: Permission denied by user
  • restricted: Restricted by device policy
  • unknown: Error or unknown state

Microphone Permission Status #

  • undetermined: User hasn't been asked yet
  • granted: Permission granted
  • denied: Permission denied by user
  • unknown: Error or unknown state

Each status includes:

  • canUse*: Whether the permission is granted right now
  • canRequest: Whether permission dialog can be shown
  • needsSettings: Whether user must go to Settings to grant permission
  • description: Human-readable description
  • rawValue: Native platform raw value
  • timestamp: When status was retrieved
  • deviceModel: Device model information
  • systemVersion: 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 #

  1. Missing Info.plist keys: iOS terminates the app on a permission request if NSCameraUsageDescription / NSMicrophoneUsageDescription are absent. See iOS Setup.
  2. Permission dialog not showing: Try the triggerMicrophonePermissionDialog() method for microphone permissions
  3. Status not updating: Use the refresh functionality in the example app
  4. Unexpected behavior: Enable debug logging and check console output
  5. Testing: Use the built-in test functions to verify functionality

Contributing #

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License #

MIT — see LICENSE for details.

0
likes
160
points
0
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Reliable native iOS camera and microphone permission handling for Flutter, calling AVFoundation directly instead of going through permission_handler.

Repository (GitHub)
View/report issues

Topics

#permissions #camera #microphone #ios

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on ios_permission

Packages that implement ios_permission