【问题标题】:Get GPS without alert view with ROOT permission(jailbreak)获取具有 ROOT 权限的 GPS 没有警报视图(越狱)
【发布时间】:2012-06-18 15:32:43
【问题描述】:

如何在没有警报视图的情况下获取 gps(越狱 iphone)?

NSString *newText;

CLLocationManager * locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

CLLocation* location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];

newText = [[NSString alloc] initWithFormat: @"Your Position : %f %f", coordinate.latitude, coordinate.longitude];

NSLog(@"%@", newText);

【问题讨论】:

  • 听起来你正在尝试编写一个未经用户许可获取用户位置的程序......

标签: iphone objective-c ios gps jailbreak


【解决方案1】:
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:@"your app bundle identifier"];

要使用此功能,您的应用程序权利应具有 com.apple.locationd.authorizeapplications 键并将布尔值设置为 true。

更新

找到了更好的解决方案。添加到您的应用程序权利com.apple.locationd.preauthorized 键,布尔值设置为true。这将对您的应用程序进行预授权,因此您可以在没有任何用户许可或私有 API 的情况下请求位置。我在装有 iOS 5-7 的 iPhone 4S、5、5C、5S 上对其进行了测试。它可以在没有任何 Info.plist 的守护程序或命令行工具中工作,只是普通的二进制文件。

为了测试我使用了以下代码

#import <CoreLocation/CoreLocation.h>

@interface LocationDelegate : NSObject<CLLocationManagerDelegate>
@end

@implementation

-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations
{
    NSLog(@"%@", locations);
}

@end

int main(int argc, char * argv[])
{
    LocationDelegate* delegate = [[LocationDelegate alloc] init];

    CLLocationManager* manager = [[CLLocationManager alloc] init];
    manager.delegate = delegate;
    [manager startUpdatingLocation];

    [[NSRunLoop currentRunLoop] run];

    return 0;
}

【讨论】:

  • ...当然要记住在本地声明 + (void) setAuthorizationStatus: (BOOL)status forBundleIdentifier: (NSString*)id;,因为那是私有 API。
  • 好吧,使用 Xcode / CLang / ARC 的默认设置,it's no longer a warning。这是一个错误,您的项目将无法构建。即使您在项目中使用较旧的工具/设置,忽略警告也不是一个好主意。它使编译器为您发现的其他合法问题变得更加困难。
  • @creker 我将此记录添加到我的 plist &lt;key&gt;com.apple.locationd.authorizeapplications&lt;/key&gt; &lt;true/&gt; 和此代码在我的项目中[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:@"your app bundle identifier"];[CLLocationManager authorizationStatus] 返回kCLAuthorizationStatusRestricted
  • 您应该输入应用的实际捆绑 ID,而不是“您的应用程序包标识符”。那就只看有没有得到坐标,不要看状态。
  • 没关系。我的应用程序也只是没有任何 GUI 的守护程序。我正在使用 Xcode 构建它们,因此我有一个带有捆绑 ID 的有效 Info.plist 文件。这是我传递给提到的函数的包 ID。在 iOS 5 和 6 上完美运行。
猜你喜欢
  • 1970-01-01
  • 2011-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-02
  • 2013-04-04
  • 2018-01-05
  • 1970-01-01
相关资源
最近更新 更多