Commit a1b96e69 by Maurits van Beusekom Committed by GitHub

Merge pull request #182 from ty0x2333/ios_permission_selectivity

Fix issue #26
parents 5784c0de b9f9e4b5
......@@ -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.
By default, all the permissions listed [here](https://github.com/Baseflow/flutter-permission-handler#list-of-available-permissions) are supported.
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
> # 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
......
......@@ -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
# 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
......@@ -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,
......
......@@ -84,7 +84,11 @@
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:
......
......@@ -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
#else
#import "UnknownPermissionStrategy.h"
@interface AudioVideoPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -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;
}
......@@ -32,9 +41,19 @@
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;
......@@ -67,3 +86,10 @@
}
@end
#else
@implementation AudioVideoPermissionStrategy
@end
#endif
......@@ -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
#else
#import "UnknownPermissionStrategy.h"
@interface ContactPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "ContactPermissionStrategy.h"
#if PERMISSION_CONTACTS
@implementation ContactPermissionStrategy
......@@ -94,3 +95,10 @@
});
}
@end
#else
@implementation ContactPermissionStrategy
@end
#endif
......@@ -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
#else
#import "UnknownPermissionStrategy.h"
@interface EventPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,14 +5,23 @@
#import "EventPermissionStrategy.h"
#if PERMISSION_EVENTS | PERMISSION_REMINDERS
@implementation EventPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
if (permission == PermissionGroupCalendar) {
#if PERMISSION_EVENTS
return [EventPermissionStrategy permissionStatus:EKEntityTypeEvent];
#else
return PermissionStatusUnknown;
#endif
} else if (permission == PermissionGroupReminders) {
#if PERMISSION_REMINDERS
return [EventPermissionStrategy permissionStatus:EKEntityTypeReminder];
#else
return PermissionStatusUnknown;
#endif
}
return PermissionStatusUnknown;
......@@ -33,9 +42,19 @@
EKEntityType entityType;
if (permission == PermissionGroupCalendar) {
#if PERMISSION_EVENTS
entityType = EKEntityTypeEvent;
#else
completionHandler(PermissionStatusUnknown);
return;
#endif
} else if (permission == PermissionGroupReminders) {
#if PERMISSION_REMINDERS
entityType = EKEntityTypeReminder;
#else
completionHandler(PermissionStatusUnknown);
return;
#endif
} else {
completionHandler(PermissionStatusUnknown);
return;
......@@ -69,3 +88,10 @@
}
@end
#else
@implementation EventPermissionStrategy
@end
#endif
......@@ -3,11 +3,21 @@
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
//
#import <CoreLocation/CoreLocation.h>
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#if PERMISSION_LOCATION
#import <CoreLocation/CoreLocation.h>
@interface LocationPermissionStrategy : NSObject <PermissionStrategy, CLLocationManagerDelegate>
- (instancetype)initWithLocationManager;
@end
#else
#import "UnknownPermissionStrategy.h"
@interface LocationPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "LocationPermissionStrategy.h"
#if PERMISSION_LOCATION
@implementation LocationPermissionStrategy {
CLLocationManager *_locationManager;
......@@ -154,3 +155,10 @@
}
@end
#else
@implementation LocationPermissionStrategy
@end
#endif
......@@ -4,9 +4,19 @@
//
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
#include "PermissionStrategy.h"
#if PERMISSION_MEDIA_LIBRARY
#import <MediaPlayer/MediaPlayer.h>
@interface MediaLibraryPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface MediaLibraryPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "MediaLibraryPermissionStrategy.h"
#if PERMISSION_MEDIA_LIBRARY
@implementation MediaLibraryPermissionStrategy
......@@ -59,3 +60,10 @@
}
@end
#else
@implementation MediaLibraryPermissionStrategy
@end
#endif
......@@ -6,9 +6,20 @@
//
#import <Foundation/Foundation.h>
#import <UserNotifications/UserNotifications.h>
#import "PermissionStrategy.h"
#if PERMISSION_NOTIFICATIONS
#import <UserNotifications/UserNotifications.h>
@interface NotificationPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface NotificationPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -7,6 +7,8 @@
#import "NotificationPermissionStrategy.h"
#if PERMISSION_NOTIFICATIONS
@implementation NotificationPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
......@@ -73,3 +75,10 @@
}
@end
#else
@implementation NotificationPermissionStrategy
@end
#endif
......@@ -5,8 +5,18 @@
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#import <Photos/Photos.h>
#if PERMISSION_PHOTOS
#import <Photos/Photos.h>
@interface PhotoPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface PhotoPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "PhotoPermissionStrategy.h"
#if PERMISSION_PHOTOS
@implementation PhotoPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
......@@ -50,3 +51,10 @@
}
@end
#else
@implementation PhotoPermissionStrategy
@end
#endif
......@@ -3,10 +3,20 @@
// Copyright (c) 2019 The Chromium Authors. All rights reserved.
//
#import <CoreMotion/CoreMotion.h>
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#if PERMISSION_SENSORS
#import <CoreMotion/CoreMotion.h>
@interface SensorPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface SensorPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "SensorPermissionStrategy.h"
#if PERMISSION_SENSORS
@implementation SensorPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
......@@ -80,3 +81,10 @@
}
@end
#else
@implementation SensorPermissionStrategy
@end
#endif
......@@ -5,7 +5,18 @@
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
#if PERMISSION_SPEECH_RECOGNIZER
#import <Speech/Speech.h>
@interface SpeechPermissionStrategy : NSObject <PermissionStrategy>
@end
#else
#import "UnknownPermissionStrategy.h"
@interface SpeechPermissionStrategy : UnknownPermissionStrategy
@end
#endif
......@@ -5,6 +5,7 @@
#import "SpeechPermissionStrategy.h"
#if PERMISSION_SPEECH_RECOGNIZER
@implementation SpeechPermissionStrategy
- (PermissionStatus)checkPermissionStatus:(PermissionGroup)permission {
......@@ -58,3 +59,10 @@
}
@end
#else
@implementation SpeechPermissionStrategy
@end
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment