获取iPhone的iPhone位置,无需首选项位置服务设置为ON

时间:2014-09-01 14:46:25

标签: ios geolocation jailbreak iphone-privateapi location-services

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


更新01:

我按照iMokhles的说法做了,我想它应该有效,但没有任何反应。我想这是因为权利,我看到了syslog,这里记录了什么:

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

所以我将此密钥添加到权利中,但它仍然给了我这个错误。在我检查了首选项应用程序权利之后,我将这些行添加到权利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/>

1 个答案:

答案 0 :(得分:1)

以下是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>

修改 检查上面的代码

祝你好运