Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
permission_handler
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
songyanzhi
permission_handler
Commits
03429015
Unverified
Commit
03429015
authored
May 21, 2019
by
Sebastian Roth
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'android-phone-service-status' into develop
parents
6aeed0c6
71482400
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
107 additions
and
19 deletions
+107
-19
example/ios/Podfile
+1
-1
example/ios/Runner.xcodeproj/project.pbxproj
+10
-3
example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
+1
-3
example/lib/main.dart
+0
-1
ios/Classes/PermissionManager.h
+1
-0
ios/Classes/PermissionManager.m
+2
-0
ios/Classes/strategies/LocationPermissionStrategy.m
+6
-0
ios/Classes/strategies/MediaLibraryPermissionStrategy.m
+2
-3
ios/Classes/strategies/PhonePermissionStrategy.h
+17
-0
ios/Classes/strategies/PhonePermissionStrategy.m
+52
-0
ios/Classes/strategies/SpeechPermissionStrategy.m
+1
-1
lib/src/permission_handler.dart
+14
-7
No files found.
example/ios/Podfile
View file @
03429015
# Uncomment this line to define a global platform for your project
# platform :ios, '9
.0'
platform
:ios
,
'8
.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV
[
'COCOAPODS_DISABLE_STATS'
]
=
'true'
...
...
example/ios/Runner.xcodeproj/project.pbxproj
View file @
03429015
...
...
@@ -13,7 +13,6 @@
3B80C3951E831B6300D905FE
/* App.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
3B80C3931E831B6300D905FE
/* App.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
9705A1C61CF904A100538489
/* Flutter.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9740EEBA1CF902C7004384FC
/* Flutter.framework */
;
};
9705A1C71CF904A300538489
/* Flutter.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9740EEBA1CF902C7004384FC
/* Flutter.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
9740EEB41CF90195004384FC
/* Debug.xcconfig in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9740EEB21CF90195004384FC
/* Debug.xcconfig */
;
};
978B8F6F1D3862AE00F588F7
/* AppDelegate.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
7AFFD8EE1D35381100E5BB4D
/* AppDelegate.m */
;
};
97C146F31CF9000F007C117D
/* main.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
97C146F21CF9000F007C117D
/* main.m */
;
};
97C146FC1CF9000F007C117D
/* Main.storyboard in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
97C146FA1CF9000F007C117D
/* Main.storyboard */
;
};
...
...
@@ -179,7 +178,7 @@
97C146E61CF9000F007C117D
/* Project object */
=
{
isa
=
PBXProject
;
attributes
=
{
LastUpgradeCheck
=
091
0
;
LastUpgradeCheck
=
102
0
;
ORGANIZATIONNAME
=
"The Chromium Authors"
;
TargetAttributes
=
{
97C146ED1CF9000F007C117D
=
{
...
...
@@ -213,7 +212,6 @@
files
=
(
97C147011CF9000F007C117D
/* LaunchScreen.storyboard in Resources */
,
3B3967161E833CAA004F5970
/* AppFrameworkInfo.plist in Resources */
,
9740EEB41CF90195004384FC
/* Debug.xcconfig in Resources */
,
97C146FE1CF9000F007C117D
/* Assets.xcassets in Resources */
,
97C146FC1CF9000F007C117D
/* Main.storyboard in Resources */
,
);
...
...
@@ -330,6 +328,7 @@
baseConfigurationReference
=
7AFA3C8E1D35360C0083082E
/* Release.xcconfig */
;
buildSettings
=
{
ALWAYS_SEARCH_USER_PATHS
=
NO
;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED
=
YES
;
CLANG_ANALYZER_NONNULL
=
YES
;
CLANG_CXX_LANGUAGE_STANDARD
=
"gnu++0x"
;
CLANG_CXX_LIBRARY
=
"libc++"
;
...
...
@@ -339,12 +338,14 @@
CLANG_WARN_BOOL_CONVERSION
=
YES
;
CLANG_WARN_COMMA
=
YES
;
CLANG_WARN_CONSTANT_CONVERSION
=
YES
;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS
=
YES
;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE
=
YES_ERROR
;
CLANG_WARN_EMPTY_BODY
=
YES
;
CLANG_WARN_ENUM_CONVERSION
=
YES
;
CLANG_WARN_INFINITE_RECURSION
=
YES
;
CLANG_WARN_INT_CONVERSION
=
YES
;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF
=
YES
;
CLANG_WARN_OBJC_LITERAL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_RANGE_LOOP_ANALYSIS
=
YES
;
...
...
@@ -402,6 +403,7 @@
baseConfigurationReference
=
9740EEB21CF90195004384FC
/* Debug.xcconfig */
;
buildSettings
=
{
ALWAYS_SEARCH_USER_PATHS
=
NO
;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED
=
YES
;
CLANG_ANALYZER_NONNULL
=
YES
;
CLANG_CXX_LANGUAGE_STANDARD
=
"gnu++0x"
;
CLANG_CXX_LIBRARY
=
"libc++"
;
...
...
@@ -411,12 +413,14 @@
CLANG_WARN_BOOL_CONVERSION
=
YES
;
CLANG_WARN_COMMA
=
YES
;
CLANG_WARN_CONSTANT_CONVERSION
=
YES
;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS
=
YES
;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE
=
YES_ERROR
;
CLANG_WARN_EMPTY_BODY
=
YES
;
CLANG_WARN_ENUM_CONVERSION
=
YES
;
CLANG_WARN_INFINITE_RECURSION
=
YES
;
CLANG_WARN_INT_CONVERSION
=
YES
;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF
=
YES
;
CLANG_WARN_OBJC_LITERAL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_RANGE_LOOP_ANALYSIS
=
YES
;
...
...
@@ -456,6 +460,7 @@
baseConfigurationReference
=
7AFA3C8E1D35360C0083082E
/* Release.xcconfig */
;
buildSettings
=
{
ALWAYS_SEARCH_USER_PATHS
=
NO
;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED
=
YES
;
CLANG_ANALYZER_NONNULL
=
YES
;
CLANG_CXX_LANGUAGE_STANDARD
=
"gnu++0x"
;
CLANG_CXX_LIBRARY
=
"libc++"
;
...
...
@@ -465,12 +470,14 @@
CLANG_WARN_BOOL_CONVERSION
=
YES
;
CLANG_WARN_COMMA
=
YES
;
CLANG_WARN_CONSTANT_CONVERSION
=
YES
;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS
=
YES
;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE
=
YES_ERROR
;
CLANG_WARN_EMPTY_BODY
=
YES
;
CLANG_WARN_ENUM_CONVERSION
=
YES
;
CLANG_WARN_INFINITE_RECURSION
=
YES
;
CLANG_WARN_INT_CONVERSION
=
YES
;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF
=
YES
;
CLANG_WARN_OBJC_LITERAL_CONVERSION
=
YES
;
CLANG_WARN_OBJC_ROOT_CLASS
=
YES_ERROR
;
CLANG_WARN_RANGE_LOOP_ANALYSIS
=
YES
;
...
...
example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
View file @
03429015
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion =
"
091
0"
LastUpgradeVersion =
"
102
0"
version =
"1.3"
>
<BuildAction
parallelizeBuildables =
"YES"
...
...
@@ -26,7 +26,6 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
shouldUseLaunchSchemeArgsEnv =
"YES"
>
<Testables>
</Testables>
...
...
@@ -46,7 +45,6 @@
buildConfiguration =
"Debug"
selectedDebuggerIdentifier =
"Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier =
"Xcode.DebuggerFoundation.Launcher.LLDB"
language =
""
launchStyle =
"0"
useCustomWorkingDirectory =
"NO"
ignoresPersistentStateOnLaunch =
"NO"
...
...
example/lib/main.dart
View file @
03429015
...
...
@@ -28,7 +28,6 @@ class MyApp extends StatelessWidget {
.
where
((
PermissionGroup
permission
)
{
if
(
Platform
.
isIOS
)
{
return
permission
!=
PermissionGroup
.
unknown
&&
permission
!=
PermissionGroup
.
phone
&&
permission
!=
PermissionGroup
.
sms
&&
permission
!=
PermissionGroup
.
storage
&&
permission
!=
...
...
ios/Classes/PermissionManager.h
View file @
03429015
...
...
@@ -15,6 +15,7 @@
#import "LocationPermissionStrategy.h"
#import "MediaLibraryPermissionStrategy.h"
#import "PermissionStrategy.h"
#import "PhonePermissionStrategy.h"
#import "PhotoPermissionStrategy.h"
#import "SensorPermissionStrategy.h"
#import "SpeechPermissionStrategy.h"
...
...
ios/Classes/PermissionManager.m
View file @
03429015
...
...
@@ -89,6 +89,8 @@
return
[
MediaLibraryPermissionStrategy
new
];
case
PermissionGroupMicrophone
:
return
[
AudioVideoPermissionStrategy
new
];
case
PermissionGroupPhone
:
return
[
PhonePermissionStrategy
new
];
case
PermissionGroupPhotos
:
return
[
PhotoPermissionStrategy
new
];
case
PermissionGroupReminders
:
...
...
ios/Classes/strategies/LocationPermissionStrategy.m
View file @
03429015
...
...
@@ -133,6 +133,9 @@
}
}
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
switch
(
authorizationStatus
)
{
case
kCLAuthorizationStatusNotDetermined
:
return
PermissionStatusUnknown
;
...
...
@@ -145,6 +148,9 @@
default
:
return
PermissionStatusUnknown
;
}
#pragma clang diagnostic pop
}
@end
ios/Classes/strategies/MediaLibraryPermissionStrategy.m
View file @
03429015
...
...
@@ -43,7 +43,7 @@
return
PermissionStatusUnknown
;
}
+
(
PermissionStatus
)
determinePermissionStatus
:
(
MPMediaLibraryAuthorizationStatus
)
authorizationStatus
{
+
(
PermissionStatus
)
determinePermissionStatus
:
(
MPMediaLibraryAuthorizationStatus
)
authorizationStatus
API_AVAILABLE
(
ios
(
9
.
3
))
{
switch
(
authorizationStatus
)
{
case
MPMediaLibraryAuthorizationStatusNotDetermined
:
return
PermissionStatusUnknown
;
...
...
@@ -58,4 +58,4 @@
return
PermissionStatusUnknown
;
}
@end
\ No newline at end of file
@end
ios/Classes/strategies/PhonePermissionStrategy.h
0 → 100644
View file @
03429015
//
// PhonePermissionStrategy.h
// permission_handler
//
// Created by Sebastian Roth on 5/20/19.
//
#import <Foundation/Foundation.h>
#import "PermissionStrategy.h"
NS_ASSUME_NONNULL_BEGIN
@interface
PhonePermissionStrategy
:
NSObject
<
PermissionStrategy
>
@end
NS_ASSUME_NONNULL_END
ios/Classes/strategies/PhonePermissionStrategy.m
0 → 100644
View file @
03429015
//
// PhonePermissionStrategy.m
// permission_handler
//
// Created by Sebastian Roth on 5/20/19.
//
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
#import "PhonePermissionStrategy.h"
@implementation
PhonePermissionStrategy
-
(
PermissionStatus
)
checkPermissionStatus
:(
PermissionGroup
)
permission
{
return
PermissionStatusUnknown
;
}
-
(
ServiceStatus
)
checkServiceStatus
:(
PermissionGroup
)
permission
{
// https://stackoverflow.com/a/5095058
if
(
!
[[
UIApplication
sharedApplication
]
canOpenURL
:[
NSURL
URLWithString
:
@"tel://"
]])
{
return
ServiceStatusNotApplicable
;
}
return
[
self
canDevicePlaceAPhoneCall
]
?
ServiceStatusEnabled
:
ServiceStatusDisabled
;
}
-
(
void
)
requestPermission
:(
PermissionGroup
)
permission
completionHandler
:(
PermissionStatusHandler
)
completionHandler
{
completionHandler
(
PermissionStatusUnknown
);
}
// https://stackoverflow.com/a/11595365
-
(
bool
)
canDevicePlaceAPhoneCall
{
/*
* Returns YES if the device can place a phone call
*/
// Device supports phone calls, lets confirm it can place one right now
CTTelephonyNetworkInfo
*
netInfo
=
[[
CTTelephonyNetworkInfo
alloc
]
init
];
CTCarrier
*
carrier
=
[
netInfo
subscriberCellularProvider
];
NSString
*
mnc
=
[
carrier
mobileNetworkCode
];
if
(([
mnc
length
]
==
0
)
||
([
mnc
isEqualToString
:
@"65535"
]))
{
// Device cannot place a call at this time. SIM might be removed.
return
NO
;
}
else
{
// Device can place a phone call
return
YES
;
}
}
@end
ios/Classes/strategies/SpeechPermissionStrategy.m
View file @
03429015
...
...
@@ -42,7 +42,7 @@
return
PermissionStatusUnknown
;
}
+
(
PermissionStatus
)
determinePermissionStatus
:
(
SFSpeechRecognizerAuthorizationStatus
)
authorizationStatus
{
+
(
PermissionStatus
)
determinePermissionStatus
:
(
SFSpeechRecognizerAuthorizationStatus
)
authorizationStatus
API_AVAILABLE
(
ios
(
10
.
0
))
{
switch
(
authorizationStatus
)
{
case
SFSpeechRecognizerAuthorizationStatusNotDetermined
:
return
PermissionStatusUnknown
;
...
...
lib/src/permission_handler.dart
View file @
03429015
...
...
@@ -42,13 +42,20 @@ class PermissionHandler {
/// Returns a [Future] containing the current service status for the supplied [PermissionGroup].
///
/// Notes about specific PermissionGroups:
/// - **PermissionGroup.phone** on Android:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the device lacks the TELEPHONY feature
/// 1. TelephonyManager.getPhoneType() returns PHONE_TYPE_NONE
/// 1. when no Intents can be resolved to handle the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the SIM card is missing
/// - **PermissionGroup.phone**
/// - Android:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the device lacks the TELEPHONY feature
/// 1. TelephonyManager.getPhoneType() returns PHONE_TYPE_NONE
/// 1. when no Intents can be resolved to handle the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the SIM card is missing
/// - iOS:
/// - The method will return [ServiceStatus.notApplicable] when:
/// 1. the native code can not find a handler for the `tel:` scheme
/// - The method will return [ServiceStatus.disabled] when:
/// 1. the mobile network code (MNC) is either 0 or 65535. See
/// https://stackoverflow.com/a/11595365 for details
/// - **PLEASE NOTE that this is still not a perfect indication** of the
/// devices' capability to place & connect phone calls
/// as it also depends on the network condition.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment