Skip to content

Fix issue #26 #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,88 @@ For this plugin to work you will have to add permission configuration to your `A
- [AndroidManifest.xml](https://github.com/Baseflow/flutter-permission-handler/blob/develop/example/android/app/src/main/AndroidManifest.xml) (note that there is a debug, main and profile version which are used depending on how you start your App. In general it is sufficient to add permissions only to the `main` version);
- [Info.plist](https://github.com/Baseflow/flutter-permission-handler/blob/develop/example/ios/Runner/Info.plist)

> IMPORTANT: On iOS you will have to include all permission options when you want to submit your App. This is because the `permission_handler` plugin touches all different SDKs and because the static code analyser (run by Apple upon App submission) detects this and will assert if it cannot find a matching permission option in the `Info.plist`. More information about this can be found [here](https://github.com/Baseflow/flutter-permission-handler/issues/26). Unfortunately we don't have a good solution for this.
> IMPORTANT: ~~On iOS you will have to include all permission options when you want to submit your App.~~ This is because the `permission_handler` plugin touches all different SDKs and because the static code analyser (run by Apple upon App submission) detects this and will assert if it cannot find a matching permission option in the `Info.plist`. More information about this can be found [here](https://github.com/BaseflowIT/flutter-permission-handler/issues/26).

On iOS, the permission_handler plugin use [macros](https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/ios/Classes/PermissionHandlerEnums.h) to control whether a permission is supported.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is no longer valid. Any chance to submit a pr to correct it?


By default, all the permissions listed [here](https://github.com/Baseflow/flutter-permission-handler#list-of-available-permissions) are supported.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is no longer valid. Any chance to submit a pr to correct it?


You can remove permissions you don't use by:

> 1. Add the following to your `Podfile` file:
>
> ```ruby
> post_install do |installer|
> installer.pods_project.targets.each do |target|
> target.build_configurations.each do |config|
> ... # Here are some configurations automatically generated by flutter
>
> # You can remove unused permissions here
> # for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/ios/Classes/PermissionHandlerEnums.h

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is no longer valid. Any chance to submit a pr to correct it?

> # 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=0',
>
> ## dart: PermissionGroup.reminders
> # 'PERMISSION_REMINDERS=0',
>
> ## dart: PermissionGroup.contacts
> # 'PERMISSION_CONTACTS=0',
>
> ## dart: PermissionGroup.camera
> # 'PERMISSION_CAMERA=0',
>
> ## dart: PermissionGroup.microphone
> # 'PERMISSION_MICROPHONE=0',
>
> ## dart: PermissionGroup.speech
> # 'PERMISSION_SPEECH_RECOGNIZER=0',
>
> ## dart: PermissionGroup.photos
> # 'PERMISSION_PHOTOS=0',
>
> ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
> # 'PERMISSION_LOCATION=0',
>
> ## dart: PermissionGroup.notification
> # 'PERMISSION_NOTIFICATIONS=0',
>
> ## dart: PermissionGroup.mediaLibrary
> # 'PERMISSION_MEDIA_LIBRARY=0',
>
> ## dart: PermissionGroup.sensors
> # 'PERMISSION_SENSORS=0'
> ]
>
> end
> end
> end
> ```
>
> 2. Delete the corresponding permission description in `Info.plist`
>
> e.g. when you don't need camera permission, just delete 'NSCameraUsageDescription'
>
> The following lists the relationship between `Permission` and `The key of Info.plist`:
>
> | Permission | Info.plist | Macro |
> |---|---|---|
> | PermissionGroup.calendar | NSCalendarsUsageDescription | PERMISSION_EVENTS |
> | PermissionGroup.reminders | NSRemindersUsageDescription | PERMISSION_REMINDERS |
> | PermissionGroup.contacts | NSContactsUsageDescription | PERMISSION_CONTACTS |
> | PermissionGroup.camera | NSCameraUsageDescription | PERMISSION_CAMERA |
> | PermissionGroup.microphone | NSMicrophoneUsageDescription | PERMISSION_MICROPHONE |
> | PermissionGroup.speech | NSSpeechRecognitionUsageDescription | PERMISSION_SPEECH_RECOGNIZER |
> | PermissionGroup.photos | NSPhotoLibraryUsageDescription | PERMISSION_PHOTOS |
> | PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse | NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription | PERMISSION_LOCATION |
> | PermissionGroup.notification | PermissionGroupNotification | PERMISSION_NOTIFICATIONS |
> | PermissionGroup.mediaLibrary | NSAppleMusicUsageDescription, kTCCServiceMediaLibrary | PERMISSION_MEDIA_LIBRARY |
> | PermissionGroup.sensors | NSMotionUsageDescription | PERMISSION_SENSORS |
>
> 3. Clean & Rebuild

## API

Expand Down
41 changes: 41 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,47 @@ post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'

# You can remove unused permissions here
# for more infomation: https://github.com/BaseflowIT/flutter-permission-handler/blob/develop/ios/Classes/PermissionHandlerEnums.h

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL is no longer valid. Any chance to submit a pr to correct it?

# 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=0',

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

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

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

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

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

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

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

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

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

## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=0'
]

end
end
end
76 changes: 76 additions & 0 deletions ios/Classes/PermissionHandlerEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,82 @@
// Created by Razvan Lung on 15/02/2019.
//

// ios: PermissionGroupCalendar
// Info.plist: NSCalendarsUsageDescription
// dart: PermissionGroup.calendar
#ifndef PERMISSION_EVENTS
#define PERMISSION_EVENTS 1
#endif

// ios: PermissionGroupReminders
// Info.plist: NSRemindersUsageDescription
// dart: PermissionGroup.reminders
#ifndef PERMISSION_REMINDERS
#define PERMISSION_REMINDERS 1
#endif

// ios: PermissionGroupContacts
// Info.plist: NSContactsUsageDescription
// dart: PermissionGroup.contacts
#ifndef PERMISSION_CONTACTS
#define PERMISSION_CONTACTS 1
#endif

// ios: PermissionGroupCamera
// Info.plist: NSCameraUsageDescription
// dart: PermissionGroup.camera
#ifndef PERMISSION_CAMERA
#define PERMISSION_CAMERA 1
#endif

// ios: PermissionGroupMicrophone
// Info.plist: NSMicrophoneUsageDescription
// dart: PermissionGroup.microphone
#ifndef PERMISSION_MICROPHONE
#define PERMISSION_MICROPHONE 1
#endif

// ios: PermissionGroupSpeech
// Info.plist: NSSpeechRecognitionUsageDescription
// dart: PermissionGroup.speech
#ifndef PERMISSION_SPEECH_RECOGNIZER
#define PERMISSION_SPEECH_RECOGNIZER 1
#endif

// ios: PermissionGroupPhotos
// Info.plist: NSPhotoLibraryUsageDescription
// dart: PermissionGroup.photos
#ifndef PERMISSION_PHOTOS
#define PERMISSION_PHOTOS 1
#endif

// ios: [PermissionGroupLocation, PermissionGroupLocationAlways, PermissionGroupLocationWhenInUse]
// Info.plist: [NSLocationUsageDescription, NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription]
// dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
#ifndef PERMISSION_LOCATION
#define PERMISSION_LOCATION 1
#endif

// ios: PermissionGroupNotification
// dart: PermissionGroup.notification
#ifndef PERMISSION_NOTIFICATIONS
#define PERMISSION_NOTIFICATIONS 1
#endif

// ios: PermissionGroupMediaLibrary
// Info.plist: [NSAppleMusicUsageDescription, kTCCServiceMediaLibrary]
// dart: PermissionGroup.mediaLibrary
#ifndef PERMISSION_MEDIA_LIBRARY
#define PERMISSION_MEDIA_LIBRARY 1
#endif

// ios: PermissionGroupSensors
// Info.plist: NSMotionUsageDescription
// dart: PermissionGroup.sensors
#ifndef PERMISSION_SENSORS
#define PERMISSION_SENSORS 1
#endif

typedef NS_ENUM(int, PermissionGroup) {
PermissionGroupCalendar = 0,
PermissionGroupCamera,
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/PermissionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ + (id)createPermissionStrategy:(PermissionGroup)permission {
case PermissionGroupLocation:
case PermissionGroupLocationAlways:
case PermissionGroupLocationWhenInUse:
#if PERMISSION_LOCATION
return [[LocationPermissionStrategy alloc] initWithLocationManager];
#else
return [LocationPermissionStrategy new];
#endif
case PermissionGroupMediaLibrary:
return [MediaLibraryPermissionStrategy new];
case PermissionGroupMicrophone:
Expand Down
13 changes: 11 additions & 2 deletions ios/Classes/strategies/AudioVideoPermissionStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
//

#import <AVFoundation/AVFoundation.h>
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"

#if PERMISSION_CAMERA | PERMISSION_MICROPHONE
#import <AVFoundation/AVFoundation.h>

@interface AudioVideoPermissionStrategy : NSObject <PermissionStrategy>
@end
@end

#else

#import "UnknownPermissionStrategy.h"
@interface AudioVideoPermissionStrategy : UnknownPermissionStrategy
@end

#endif
28 changes: 27 additions & 1 deletion ios/Classes/strategies/AudioVideoPermissionStrategy.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@

#import "AudioVideoPermissionStrategy.h"

#if PERMISSION_CAMERA | PERMISSION_MICROPHONE

@implementation AudioVideoPermissionStrategy

- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
if (permission == PermissionGroupCamera) {
#if PERMISSION_CAMERA
return [AudioVideoPermissionStrategy permissionStatus:AVMediaTypeVideo];
#else
return PermissionStatusUnknown;
#endif
} else if (permission == PermissionGroupMicrophone) {
#if PERMISSION_MICROPHONE
return [AudioVideoPermissionStrategy permissionStatus:AVMediaTypeAudio];
#else
return PermissionStatusUnknown;
#endif
}
return PermissionStatusUnknown;
}
Expand All @@ -32,9 +41,19 @@ - (void)requestPermission:(PermissionGroup)permission completionHandler:(Permiss
AVMediaType mediaType;

if (permission == PermissionGroupCamera) {
#if PERMISSION_CAMERA
mediaType = AVMediaTypeVideo;
#else
completionHandler(PermissionStatusUnknown);
return;
#endif
} else if (permission == PermissionGroupMicrophone) {
#if PERMISSION_MICROPHONE
mediaType = AVMediaTypeAudio;
#else
completionHandler(PermissionStatusUnknown);
return;
#endif
} else {
completionHandler(PermissionStatusUnknown);
return;
Expand Down Expand Up @@ -66,4 +85,11 @@ + (PermissionStatus)permissionStatus:(AVMediaType const)mediaType {
return PermissionStatusUnknown;
}

@end
@end

#else

@implementation AudioVideoPermissionStrategy
@end

#endif
16 changes: 13 additions & 3 deletions ios/Classes/strategies/ContactPermissionStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
//

#import <AddressBook/ABAddressBook.h>
#import <Contacts/Contacts.h>
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"

#if PERMISSION_CONTACTS

#import <AddressBook/ABAddressBook.h>
#import <Contacts/Contacts.h>

@interface ContactPermissionStrategy : NSObject <PermissionStrategy>
@end
@end

#else

#import "UnknownPermissionStrategy.h"
@interface ContactPermissionStrategy : UnknownPermissionStrategy
@end

#endif
8 changes: 8 additions & 0 deletions ios/Classes/strategies/ContactPermissionStrategy.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#import "ContactPermissionStrategy.h"

#if PERMISSION_CONTACTS

@implementation ContactPermissionStrategy

Expand Down Expand Up @@ -94,3 +95,10 @@ + (void)requestPermissionsFromAddressBook:(PermissionStatusHandler)completionHan
});
}
@end

#else

@implementation ContactPermissionStrategy
@end

#endif
14 changes: 12 additions & 2 deletions ios/Classes/strategies/EventPermissionStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
//

#import <Foundation/Foundation.h>
#import <EventKit/EventKit.h>
#import "PermissionStrategy.h"

#if PERMISSION_EVENTS | PERMISSION_REMINDERS

#import <EventKit/EventKit.h>

@interface EventPermissionStrategy : NSObject <PermissionStrategy>
@end
@end

#else

#import "UnknownPermissionStrategy.h"
@interface EventPermissionStrategy : UnknownPermissionStrategy
@end

#endif
Loading