对于 SceneDelegate,LaunchOptions 始终为零
我已经调查了重要位置。 我想在不运行应用程序时获取位置信息。 https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/using_the_significant- change_location_service
下面的代码是获取位置信息的触发器。
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if launchOptions?[.location] != nil {
locationManager.startMonitoringSignificantLocationChanges()
}
return true
}
但我遇到了一个奇怪的行为。
当应用程序通过重要位置事件启动时。
仅限 AppDelegate:launchOptions?[.location] 不为 nil
AppDelegate + SceneDelegate:launchOptions?[.location]始终为零
我无法从SceneDelegate方法获得类似的值。
如果我想使用与位置相关的 launchOptions,是否只使用 AppDelegate 更好?
I have investigated siginificant location.
I would like to get location information when not running app.
https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/using_the_significant-change_location_service
The following code is an trigger for getting location information.
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if launchOptions?[.location] != nil {
locationManager.startMonitoringSignificantLocationChanges()
}
return true
}
But I encountered a strange behavior.
When an app launch by significant location event.
AppDelegate only: launchOptions?[.location] isn’t nil
AppDelegate + SceneDelegate: launchOptions?[.location] is always nil
I couldn’t get similar value from SceneDelegate method.
If I want to use launchOptions related to location, is it better to use AppDelegate only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UIApplicationLaunchOptionsLocationKey
或launchOptions?[.location]
目前仅适用于应用程序委托生命周期(从 iOS 7.4 开始),即删除 SceneDelegate 类并删除场景清单时来自 Info.plist。要获得场景生命周期,您需要自己破解信息,例如:
Info.plist
YourApp-Bridging-Header.h
MyApplication.h< /strong>
MyApplication.m
现在您可以在场景委托中检索它,如下所示:
我通过反馈报告了场景生命周期的此限制,以便将其作为
.backgroundTask(.significantLocation) 添加到 SwiftUI
为 FB13699977 请随时在您的报告中引用。UIApplicationLaunchOptionsLocationKey
orlaunchOptions?[.location]
is currently only available (as of iOS 7.4) with app delegate life-cycle that's when you remove your SceneDelegate class and remove the scene manifest from the Info.plist.To get it with scene lifecycle you need to hack the info yourself, e.g. something like this:
Info.plist
YourApp-Bridging-Header.h
MyApplication.h
MyApplication.m
Now you can retrieve it in your scene delegate as follows:
I reported this limitation of scene life cycle via Feedback for addition to SwiftUI as a
.backgroundTask(.significantLocation)
as FB13699977 feel free to reference in your report.当您使用场景委托时,您应该使用
scene(:,willConnectTo session:,options:)
函数When you work with the scene delegate you should use
scene(:,willConnectTo session:,options:)
function instead