iOS 11 中的位置访问请求
Location Access Request in iOS 11
我在我的应用程序中请求用户位置。
locationManager.requestAlwaysAuthorization()
这行代码应该return这个警告信息:
但是,我希望用户仅在 "Don't Allow" 和 "Always Allow" 之间进行选择。如何删除 "Only While Using The App" 选项?
知道这是我在 info.plist 中包含的内容,并且从 info.plist 中的这 3 行中删除任何一行都会导致应用程序根本不显示此警报。
根据 WWDC 2017 Session 713 关于定位技术的更新,如果您想请求始终授权,则在针对 iOS 11 及更高版本进行链接时,您应该始终包含使用时说明。并且 iOS 将另外显示一个选项,以将位置用于 When-In-Use 模式。
引自session 文字记录。
So for iOS 11 we're asking all developers with Always requesting apps to additionally support the WhenInUse authorization mode. This change is both retroactive and forward-looking, so when the user updates to iOS 11, they will be able to authorize any app that requests Always authorization the WhenInUse authorization mode instead. If you link against the iOS 11 SDK, you must provide a WhenInUseUsageDescription. Otherwise, your app will be unable to request Always authorization. Furthermore, when your app requests Always authorization, we will additionally display an option to grant your app WhenInUse authorization instead. With these new three option prompts we have a new UsageDescription string as well. Your app needs to provide an AlwaysAndWhenInUse UsageDescription. Since this is a different key your app must provide it when you link against the new iOS 11 SDK. For apps linked against iOS 11 and later, Core Location will not use the old NSLocationAlways UsageDescription key.
它不再是可选的。
由于iOS11已发布,如果您的应用程序要求位置始终开启(locationManager.requestAlwaysAuthorization()
),用户将自动获得所有三个选项。
与以前的 iOS 版本不同,所有选项 都必须 显示给用户。这导致:您必须为两个选项添加一个密钥。
改编自Apple's Article - Requesting Always Authorization:
You are required to include the NSLocationWhenInUseUsageDescription
and NSLocationAlwaysAndWhenInUseUsageDescription
keys in your app's
Info.plist file. (If your app supports iOS 10 and earlier, the
NSLocationAlwaysUsageDescription
key is also required.) If those keys
are not present, authorization requests fail immediately.
如果未设置,您将在调试控制台中收到一条消息,如:
The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data
打开 Info.plist 作为源代码
并添加以下xml块:
<key>NSLocationAlwaysUsageDescription</key>
<string>Location always usage description</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location always and when in usage description</string>
<key>NSLocationUsageDescription</key>
<string>Location usage desription</string>
我在我的应用程序中请求用户位置。
locationManager.requestAlwaysAuthorization()
这行代码应该return这个警告信息:
但是,我希望用户仅在 "Don't Allow" 和 "Always Allow" 之间进行选择。如何删除 "Only While Using The App" 选项?
知道这是我在 info.plist 中包含的内容,并且从 info.plist 中的这 3 行中删除任何一行都会导致应用程序根本不显示此警报。
根据 WWDC 2017 Session 713 关于定位技术的更新,如果您想请求始终授权,则在针对 iOS 11 及更高版本进行链接时,您应该始终包含使用时说明。并且 iOS 将另外显示一个选项,以将位置用于 When-In-Use 模式。
引自session 文字记录。
So for iOS 11 we're asking all developers with Always requesting apps to additionally support the WhenInUse authorization mode. This change is both retroactive and forward-looking, so when the user updates to iOS 11, they will be able to authorize any app that requests Always authorization the WhenInUse authorization mode instead. If you link against the iOS 11 SDK, you must provide a WhenInUseUsageDescription. Otherwise, your app will be unable to request Always authorization. Furthermore, when your app requests Always authorization, we will additionally display an option to grant your app WhenInUse authorization instead. With these new three option prompts we have a new UsageDescription string as well. Your app needs to provide an AlwaysAndWhenInUse UsageDescription. Since this is a different key your app must provide it when you link against the new iOS 11 SDK. For apps linked against iOS 11 and later, Core Location will not use the old NSLocationAlways UsageDescription key.
它不再是可选的。
由于iOS11已发布,如果您的应用程序要求位置始终开启(locationManager.requestAlwaysAuthorization()
),用户将自动获得所有三个选项。
与以前的 iOS 版本不同,所有选项 都必须 显示给用户。这导致:您必须为两个选项添加一个密钥。
改编自Apple's Article - Requesting Always Authorization:
You are required to include the
NSLocationWhenInUseUsageDescription
andNSLocationAlwaysAndWhenInUseUsageDescription
keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, theNSLocationAlwaysUsageDescription
key is also required.) If those keys are not present, authorization requests fail immediately.
如果未设置,您将在调试控制台中收到一条消息,如:
The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with string values explaining to the user how the app uses this data
打开 Info.plist 作为源代码
并添加以下xml块:
<key>NSLocationAlwaysUsageDescription</key>
<string>Location always usage description</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location always and when in usage description</string>
<key>NSLocationUsageDescription</key>
<string>Location usage desription</string>