gpt4 book ai didi

ios - 在没有首选项的情况下在 iOS 中获取 iPhone 位置 位置服务设置为 ON

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:38 25 4
gpt4 key购买 nike

我正在编写一个类似于 Chris Alvares daemon 的守护进程.我想在未经用户许可的情况下在后台获取设备位置。如果“设置”中的 Location Services 首选项设置为 ON,那么我获取位置没有问题。为此,我将 bool 值设置为 true 的 com.apple.locationd.preauthorized 键添加到我的可执行权限中。问题是当 Location Services 关闭时。在这种情况下,当我想要获取设备位置时,会弹出一个 UIAlertView 告诉用户位置服务已关闭。基本上有两种方法,但我不知道它们是否可行。首先,以编程方式打开/关闭设置中的位置服务首选项。其次,使用另一个代码获取位置,无需将位置服务设置为 ON


更新 01:

我按照 iMokhles 所说的做了,我想它应该可以工作,但没有任何反应。我想这是因为权利,我看到了系统日志,这是记录的内容:

iPhone locationd[44] <Error>: Entitlement com.apple.locationd.authorizeapplications required to use _CLDaemonSetLocationServicesEnabled
iPhone myDaemon[3443] <Error>: CoreLocation: CLInternalSetLocationServicesEnabled failed

所以我将这个 key 添加到权利中,但它仍然给我这个错误。在我检查了 Preferences app entitlement 之后,我将这些行添加到 entitlements plist 中,但同样没有任何反应。

<key>com.apple.locationd.authorizeapplications</key>
<true/>
<key>com.apple.locationd.defaults_access</key>
<true/>
<key>com.apple.locationd.effective_bundle</key>
<true/>
<key>com.apple.locationd.status</key>
<true/>

最佳答案

这是来自 FlipSwitch 的示例 Location Switch

在标题中声明

@interface CLLocationManager
+ (id)sharedManager;
+ (BOOL)locationServicesEnabled;
+ (void)setLocationServicesEnabled:(BOOL)enabled;
@end

然后就可以使用下面的代码访问了检查是否启用

if([[[objc_getClass("CLLocationManager") sharedManager] locationServicesEnabled] {
// Enabled
} else {
// Disabled
}

并启用/禁用定位

[objc_getClass("CLLocationManager") setLocationServicesEnabled:YES];
[objc_getClass("CLLocationManager") setLocationServicesEnabled:NO];

并且不要忘记导入 CoreLocation Framework ;)和

#import <objc/runtime.h>

编辑检查上面的代码

祝你好运

关于ios - 在没有首选项的情况下在 iOS 中获取 iPhone 位置 位置服务设置为 ON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25608339/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com