6

他のクラスで電話の座標を簡単に取得するためのヘルパー クラスを作成しようとしています。UIViewControllerが実装されたチュートリアルに従いましたが、<CLLocationManagerDelegate>機能しました。単純な で同じことをしようとしましたNSObjectが、デリゲートはもう呼び出されませんでした。

これは私が持っているコードです:

PSCoordinates.h

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

@interface PSCoordinates : NSObject <CLLocationManagerDelegate>

@property (nonatomic, retain) CLLocationManager* locationManager;


@end

PSCoordinates.m

#import "PSCoordinates.h"

@implementation PSCoordinates

- (id) init {
    self = [super init];

    if (self) {
        self.locationManager = [[CLLocationManager alloc] init];
        if ([CLLocationManager locationServicesEnabled])
        {
            self.locationManager.delegate = self;
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            self.locationManager.distanceFilter = 100.0f;
            NSLog(@"PSCoordinates init");
            [self.locationManager startUpdatingLocation];
        }
    }
    return self;
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"Géolocalisation : %@",[newLocation description]);
}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    NSLog(@"Géolocalisation (erreur) : %@",[error description]);

}


@end

呼んで呼んでる

PSCoordinates * coordinates = [[PSCoordinates alloc] init];

ボタンを押すとき。NSLog を見ると init が機能していますPSCoordinates init

同じ問題を抱えている人々の他のトピックを見つけましたが、答えのどれもそれを解決しませんでした.

どうぞよろしくお願いいたします。

4

1 に答える 1