Request location access for trusted networks

Policy changed in iOS 13.
This commit is contained in:
Davide De Rosa 2019-10-21 00:01:40 +02:00
parent 802a4a4586
commit fbe7d776e7
2 changed files with 28 additions and 6 deletions

View File

@ -11,15 +11,15 @@
<dict>
<key>CFBundleTypeName</key>
<string>All files</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.content</string>
<string>public.data</string>
</array>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
<key>CFBundleExecutable</key>
@ -42,6 +42,8 @@
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Trusted networks</string>
<key>NSUserActivityTypes</key>
<array>
<string>ConnectVPNIntent</string>
@ -82,10 +84,10 @@
<false/>
<key>com.algoritmico.Passepartout.config</key>
<dict>
<key>group_id</key>
<string>group.$(CFG_GROUP_ID)</string>
<key>appstore_id</key>
<string>$(CFG_APPSTORE_ID)</string>
<key>group_id</key>
<string>group.$(CFG_GROUP_ID)</string>
</dict>
</dict>
</plist>

View File

@ -26,6 +26,7 @@
import UIKit
import NetworkExtension
import MBProgressHUD
import CoreLocation
import TunnelKit
import PassepartoutCore
import Convenience
@ -39,6 +40,8 @@ class ServiceViewController: UIViewController, StrongTableHost {
@IBOutlet private weak var itemEdit: UIBarButtonItem!
private let locationManager = CLLocationManager()
private let downloader = FileDownloader(
temporaryURL: GroupConstants.App.cachesURL.appendingPathComponent("downloaded.tmp"),
timeout: AppConstants.Web.timeout
@ -339,6 +342,23 @@ class ServiceViewController: UIViewController, StrongTableHost {
}
private func trustCurrentWiFi() -> Bool {
if #available(iOS 13, *) {
let auth = CLLocationManager.authorizationStatus()
switch auth {
case .authorizedAlways, .authorizedWhenInUse:
break
case .denied:
// TODO: alert when location denied
return false
default:
locationManager.requestWhenInUseAuthorization()
// TODO: auto-invoke trustCurrentWiFi() again when location granted
return false
}
}
if #available(iOS 12, *) {
IntentDispatcher.donateTrustCurrentNetwork()
IntentDispatcher.donateUntrustCurrentNetwork()