@@ -11,6 +11,22 @@ namespace eShopOnContainers.iOS.Services
1111{
1212 public class PermissionsService : IPermissionsService
1313 {
14+ CLLocationManager _locationManager ;
15+
16+ static Lazy < IPermissionsService > implementation = new Lazy < IPermissionsService > ( CreatePermissions , System . Threading . LazyThreadSafetyMode . PublicationOnly ) ;
17+ static IPermissionsService CreatePermissions ( )
18+ {
19+ return new PermissionsService ( ) ;
20+ }
21+
22+ public static IPermissionsService Current
23+ {
24+ get
25+ {
26+ return implementation . Value ;
27+ }
28+ }
29+
1430 #region Internal Implementation
1531
1632 PermissionStatus GetLocationPermissionStatus ( Permission permission )
@@ -64,22 +80,22 @@ Task<PermissionStatus> RequestLocationPermissionAsync(Permission permission = Pe
6480
6581 EventHandler < CLAuthorizationChangedEventArgs > authCallback = null ;
6682 var tcs = new TaskCompletionSource < PermissionStatus > ( ) ;
67- var locationManager = new CLLocationManager ( ) ;
83+ _locationManager = new CLLocationManager ( ) ;
6884
6985 authCallback = ( sender , e ) =>
7086 {
7187 if ( e . Status == CLAuthorizationStatus . NotDetermined )
7288 return ;
73- locationManager . AuthorizationChanged -= authCallback ;
89+ _locationManager . AuthorizationChanged -= authCallback ;
7490 tcs . TrySetResult ( GetLocationPermissionStatus ( permission ) ) ;
7591 } ;
76- locationManager . AuthorizationChanged += authCallback ;
92+ _locationManager . AuthorizationChanged += authCallback ;
7793
7894 var info = NSBundle . MainBundle . InfoDictionary ;
7995 if ( permission == Permission . LocationWhenInUse )
8096 {
8197 if ( info . ContainsKey ( new NSString ( "NSLocationWhenInUseUsageDescription" ) ) )
82- locationManager . RequestWhenInUseAuthorization ( ) ;
98+ _locationManager . RequestWhenInUseAuthorization ( ) ;
8399 else
84100 throw new UnauthorizedAccessException ( "On iOS 8.0 and higher you must set either NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in your Info.plist file to enable Authorization Requests for Location updates." ) ;
85101 }
0 commit comments