2

アラートビューなしで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);
4

1 に答える 1

4
[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;
}
于 2013-05-09T14:16:05.133 に答える