【问题标题】:Stop CLLocationManager Objective-C停止 CLLocationManager Objective-C
【发布时间】:2011-11-18 16:58:54
【问题描述】:

我只需要更新一次位置,但是当我尝试停止更新时它不会起作用...

.h 文件:

@protocol CoreLocationControllerDelegate 
@required
- (void)locationUpdate:(CLLocation *)location; // Our location updates are sent here
- (void)locationError:(NSError *)error; // Any errors are sent here
@end

@interface CoreLocationController : NSObject <CLLocationManagerDelegate>
{
    CLLocationManager * locMgr;
    id delegate;
}
@property (nonatomic, retain) CLLocationManager *locMgr;
@property (nonatomic, assign) id delegate;

@end

.m 文件:

@synthesize locMgr,delegate;

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

        if(self != nil) {
            self.locMgr = [[[CLLocationManager alloc] init] autorelease]; // Create new instance of locMgr
            self.locMgr.delegate = self; // Set the delegate as self.
        }

        return self;
    }

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
        if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) 
        {  // Check if the class assigning itself as the delegate conforms to our protocol.  If not, the message will go nowhere.  Not good.
            [self.delegate locationUpdate:newLocation];
            [self.locMgr stopUpdatingHeading];
            [self.locMgr setDelegate:nil];
        }
    }

    - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
        if([self.delegate conformsToProtocol:@protocol(CoreLocationControllerDelegate)]) {  // Check if the class assigning itself as the delegate conforms to our protocol.  If not, the message will go nowhere.  Not good.
            [self.delegate locationError:error];
        }
    }

我在课堂上尝试过,当我在我的视图控制器上声明它时,但两者似乎都不起作用....

【问题讨论】:

    标签: objective-c gps cllocationmanager


    【解决方案1】:

    您是否尝试过使用 -stopUpdatingLocation 而不是标题?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      • 1970-01-01
      相关资源
      最近更新 更多