0

ユーザーの場所を表示するプログラムを作成するために、このチュートリアルに従っています。Xcode に場所をシミュレートするように指示しましたが、シミュレーターでも、アプリケーションが場所を追跡できるようになっていることを確認しました。ただし、コンソールには何も記録されていません。

ヘッダー ファイル:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}

@end

そしてメインファイル:

#import "WhereamiViewController.h"

@implementation WhereamiViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {
        locationManager = [[CLLocationManager alloc] init];
        [locationManager setDelegate:self];
        [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
        [locationManager setPausesLocationUpdatesAutomatically:NO];
        [locationManager startUpdatingLocation];
    }

    return self;
}

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

- (void)locationManager:(CLLocationManager *)manager
    didFailWithError:(NSError *)error
{
    NSLog(@"Error: %@", error);
}

@end
4

1 に答える 1

1

私は答えについて100%確信が持てませんが、これが私が得たものです。
iOS 7 では、アプリがフォアグラウンドにある場合にのみ位置情報の取得が許可されます。でコードを記述するinitwithNibNameと、アプリは実際にはフォアグラウンドではなく、xib ファイルとすべてからコントロールを作成します。そのため、OS は場所の更新を提供しません。

于 2013-11-28T12:20:52.753 に答える