2012-06-18 30 views
2

我怎样才能得到没有警报视图(越狱iPhone)的GPS?获取GPS无警戒视图ROOT权限(越狱)

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); 
+0

听起来你想写抓住用户的位置信息未经其许可...... – C0deH4cker

回答

4
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:@"your app bundle identifier"]; 

要使用此应用程序的权利应该设置为true布尔值com.apple.locationd.authorizeapplications关键。

UPDATE

找到更好的解决方案。将布尔值设置为true的应用程序权利com.apple.locationd.preauthorized添加到您的应用程序中。这将预先授权您的应用程序,以便您可以在没有任何用户权限或私有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; 
} 
+0

程序... rembering,当然,在本地声明'+(void)setAuthorizationStatus:(BOOL)状态forBundleIdentifier:(NSString *)id;',因为这是私人API。 – Nate

+0

但是,如果您不介意编译器警告,则不必担心。 – creker

+0

好吧,用Xcode/CLang/ARC得到的默认设置,[它不再是警告](http://stackoverflow.com/a/13486095/119114)。这是**错误**,并且您的项目不会生成。即使您为项目使用较旧的工具/设置,忽略警告也不是一个好主意。这使得难以捕捉到编译器为您找到的其他合法问题。 – Nate