【问题标题】:CLLocationmanager setAuthorizationStatus doesn't work (jailbreak)CLLocationmanager setAuthorizationStatus 不起作用(越狱)
【发布时间】:2013-12-20 04:24:49
【问题描述】:

我有 6.1.3 iOS 的越狱设备。我也有应该给我坐标的命令行工具。与位置有关的代码在普通应用程序中完美运行,但在命令行中却不行。

我发现了类似的问题,但它似乎不起作用:Get GPS without alert view with ROOT permission(jailbreak)

- (void) start
{
NSLog(@"Started");
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
{
    NSLog(@"%i", [CLLocationManager authorizationStatus]);
}

//[locationManager setAuthorizationStatus:YES forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
NSLog(@"%@", [[NSBundle mainBundle] bundleIdentifier]);
NSLog(@"%@", [[NSBundle mainBundle] bundlePath]);
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
{
    NSLog(@"%i", [CLLocationManager authorizationStatus]);
}

[locationManager startUpdatingLocation];

}

所以它总是将 0 记录为授权状态 = kCLAuthorizationStatusNotDetermined。

在构建后,我还添加了带有 ldid 的应用权利

com.apple.locationd.authorizeapplications

键设置为真。也对 Info.plist 进行了一些实验,但仍然

didUpdatedLocation

从不触发。

提前致谢!

如果需要,这是我的主要内容:

#import <Foundation/Foundation.h>
#import "locateClass.h"

int main (int argc, const char * argv[])
{

    @autoreleasepool
    {   
        // insert code here...
        NSLog(@"Hello, World!");
        locateClass *loc = [[locateClass alloc] init];
        [loc start];
    }
    return 0;
}

我也在使用 iOSOpenDev

更新:

如果我不使用 Info.plist,使用此代码,我在控制台中有此代码:

iPhone-AppServer Saimon[841] <Warning>: Hello, World!
iPhone-AppServer Saimon[841] <Warning>: Started
iPhone-AppServer Saimon[841] <Warning>: 1
iPhone-AppServer Saimon[841] <Warning>: (null)
iPhone-AppServer Saimon[841] <Warning>: /private/var/mobile/docs/fromMac/Debug-iphoneos
iPhone-AppServer Saimon[841] <Warning>: 1
iPhone-AppServer awdd[842] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
iPhone-AppServer awdd[842] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.

如果我这样做 - 这样的输出:

iPhone-AppServer Saimon[854] <Warning>: Hello, World!
iPhone-AppServer Saimon[854] <Warning>: Started
iPhone-AppServer locationd[362] <Warning>: Launch Services: Registering unknown app identifier com.apple.xcode.dsym.Saimon failed
iPhone-AppServer locationd[362] <Warning>: Launch Services: Unable to find app identifier com.apple.xcode.dsym.Saimon
iPhone-AppServer Saimon[854] <Warning>: 0
iPhone-AppServer Saimon[854] <Warning>: com.apple.xcode.dsym.Saimon
iPhone-AppServer Saimon[854] <Warning>: /private/var/mobile/docs/fromMac/Debug-iphoneos
iPhone-AppServer Saimon[854] <Warning>: 0
iPhone-AppServer awdd[855] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
iPhone-AppServer awdd[855] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.

【问题讨论】:

  • 您确定[[NSBundle mainBundle] bundleIdentifier] 会返回您的捆绑包ID吗?我没记错,它不适用于纯二进制应用程序,因为没有包,因此没有包 ID。它适用于普通应用程序,因为它们是作为捆绑包安装的。尝试只传递一些字符串,如 @"com.company.myapp" 作为捆绑 ID。当我想在守护进程中获取位置时,这就是我所做的。
  • 我把 Info.plist 文件放在二进制文件附近,所以当我启动二进制文件时,我有 bundleId 和状态 0。如果我删除 Info.plist,那么我没有 bundleId 和状态 1。你知道,关于 setAuthorizationStatus 的编译器警告:找不到类方法“+setAuthorizationStatus:forBundleIdentifier:”(返回类型默认为“id”)可以吗?我没有在任何地方声明。
  • 是的,这很正常。做了一个快速测试 - 它对我有用。使用与您完全相同的代码并获得kCLAuthorizationStatusAuthorized 作为状态。不知道didUpdateLocationlocation 属性确实包含位置。
  • location 属性可以,但纬度和经度为 0.0。你使用 iOSOpenDev 吗? Semitethered越狱会影响它吗?另外我想我应该补充一点,我在使用 ldid 构建后添加了权利: ldid -S//entitlements.xml /binary
  • 不,我只是使用 Xcode 将它构建为一个普通的 iOS 应用程序。 “Semitethered越狱会影响它吗”我不这么认为。使用ldid -e 检查权限是否确实在二进制文件中。启动应用程序时还要检查控制台。有时 iOS 会在其中记录一些有用的信息。

标签: ios cllocationmanager jailbreak


【解决方案1】:

如何加载 info.plist?因为它返回失败...

Registering unknown app identifier com.apple.xcode.dsym.Saimon failed

【讨论】:

  • 我只是把它放在二进制目录中
  • 这很正常。我在我的应用程序中也看到了这一点。
  • 试试这个 NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier] 返回你的Bundle ID还是null
  • 你认为com.apple.xcode.dsym.Saimon 来自哪里? [[NSBundle mainBundle] bundleIdentifier] 没问题,我已经问过了。这个错误信息是正常的。我在我的应用程序中也看到了它,但他们可以授权自己并获取位置。
  • 我也有同样的问题。我已将 plist 与二进制文件放在一起,但它仍然显示“启动服务:注册未知应用标识符 'com.app.magic' 失败”。任何建议都将受到高度赞赏。
【解决方案2】:

好吧,我发现解决方法不是那么容易。

一步一步。

要授权自己,您应该停止定位过程,但 killall -9 locationd 不会帮助您。阻止它:launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

然后以这种方式编辑 /var/root/Library/Caches/locationd/clients.plist 文件:

Root
    |__<your_bundleid> (Dictionary)
        |__Whitelisted (Boolean)  -  NO
        |__BundleId (String)  -  <yourBundleID>
        |__Authorized (Boolean)  -  YES
        |__Executable (String)  -  <path_to_your_binary>
        |__Registered (String)  -  <path_to_your_binary>

然后开始定位:

launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

在此之后可以获取位置,但是在命令行工具中didUpdatedLocations 方法不会触发,还有一个问题:大约一分钟后你[CLLocationManager AuthenticationStatus] 会给你拒绝状态,所以你需要手动再次编辑 plist 并从 bundleid 字典中删除 TimeMissing 键。

这是自我注册后为我工作的代码:

while (1){
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

    CLLocation *location = locationManager.location;

    if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
    {
        NSLog(@"%i", [CLLocationManager authorizationStatus]);
        if( [CLLocationManager authorizationStatus] == 2)
        {
            system("ps ax | grep locationd");
            system("launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist");
            NSString* plistPath = [[NSString alloc] initWithString:@"/var/root/Library/Caches/locationd/clients.plist"];
            NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
            NSMutableDictionary *myBundle = [plist objectForKey:[[NSBundle mainBundle] bundleIdentifier]];
            [myBundle removeObjectForKey:@"TimeMissing"];
            NSLog(@"Relaunching");
            [plist setObject:myBundle forKey:[[NSBundle mainBundle] bundleIdentifier]];
            [plist writeToFile:@"/var/root/Library/Caches/locationd/clients.plist" atomically:YES];
            system("launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist");
        }

    }

    NSLog(@"Coordinates are %f %f %f %f",
          location.coordinate.latitude,
          location.coordinate.longitude,
          location.horizontalAccuracy,
          location.verticalAccuracy);

    if ( location.coordinate.latitude == 0 && location.coordinate.longitude == 0)
    {
        NSLog(@"Nulss");
        system("launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist");
        system("launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist");
    }
    else
    {
        NSLog(@"Got IT");
        //[locationManager stopUpdatingLocation];
        //break;
    }
    sleep(10);
}

在 iOS6 和 iOS7 上测试。

【讨论】:

  • 这很奇怪。我在我的守护进程中使用setAuthorizationStatus:forBundleIdentifier: 来获取位置。一切都在 iOS 5-7 上运行。对于 iOS4,我使用与您类似的方法。我通过didUpdatedLocations: 方法接收位置事件。不管是不是命令行工具。我只能想到一件事。您的应用程序中是否有正在运行的运行循环?显然,没有它,您将不会收到任何事件。如果是命令行工具,你必须自己运行它。
  • 嗨!是的,我有 runLoop,我在其中添加了计时器,调用 NSLog(@"Coordinates are %f %f %f %f", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy, location.verticalAccuracy); 它提供了位置,但 didUpdateLocations 不会触发
  • 在这里查看我的更新stackoverflow.com/questions/11086083/…
猜你喜欢
  • 2014-01-27
  • 1970-01-01
  • 1970-01-01
  • 2012-07-26
  • 2019-01-24
  • 2014-01-12
  • 2020-10-23
  • 2013-01-20
  • 2016-05-24
相关资源
最近更新 更多