私は、地図のアプリケーションにユーザーを送信するボタンに取り組んでいます。問題は、ボタンを一度クリックして場所のアクセス権を拒否した場合、次回にボタンをクリックしたときにアプリが再びアクセス権を要求しないということです。ユーザーが「地図の許可を許可する際に1回だけ」を持っているようです。iOS Swiftで場所の許可を取得しようとしています
以下は、プログラムでコールバック関数を使用してボタンを作成するために使用するコードです。 「カスタムiOSターゲットのプロパティ」のスクリーンショットもあります。ここでは、ユーザーの場所を使用できるようにプライバシー - ロケーションの使用説明を含めています。
directionsButton.addTarget(self, action: #selector(getDirection), for: UIControlEvents.touchUpInside)
func getDirection(sender: UIButton!) {
print("1")
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse ||
CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedAlways){
let url = URL(string: "http://maps.apple.com/?daddr=60.79281049999999,10.688968899999963")
if (UIApplication.shared.canOpenURL(url!)) {
UIApplication.shared.openURL(url!)
} else {
print("Error")
}
print("2")
} else{
LocationManager.requestWhenInUseAuthorization()
print("3")
}
print("4")
}
/*
- Callback function for changes in location permissions
*/
func locationManager(_ manager: CLLocationManager,
didChangeAuthorization status: CLAuthorizationStatus){
print("change in auth")
if(CLLocationManager.authorizationStatus() == CLAuthorizationStatus.authorizedWhenInUse){
let url = URL(string: "http://maps.apple.com/?daddr=60.79281049999999,10.688968899999963")
if (UIApplication.shared.canOpenURL(url!)) {
UIApplication.shared.openURL(url!)
} else {
print("Error")
}
} else{
self.view.makeToast("Couldn't get location permission", duration: 3.0, position: .bottom)
}
}
Picture of permissions added in the info-file