사용자의 위치 업데이트를 수신하는 방법에 대한 대부분의 자습서를 읽고 준수했다고 생각합니다. CoreLocation을 가져오고 올바른 델리게이트 프로토콜을 구현하는 클래스 (UserTracker)가 있습니다. 나는 또한 올바른 방법을 구현했습니다.위치 관리자가 작동하지 않음, 세마포 오류, 대리인이 호출되지 않음, 이유는 무엇입니까?
-(bool)test
{
UserTracker * ut = [[UserTracker alloc] init];
[ut startTracking];
[NSThread sleepForTimeInterval:30];
[ut stopTracking];
NSLog(@"Accumulated distance is %f m", [pt sumDist]);
return true;
}
나는 다음과 오류가 나타납니다 : 문제는 내가이 방법으로 클래스를 테스트 할 때이다 (? 이것이 문제) 모두이 방법에 의해 동일한 스레드에서 실행됩니다
libdispatch.dylib`dispatch_semaphore_signal:
0x1e07e02: movl 4(%esp), %eax
0x1e07e06: movl $1, %ecx
0x1e07e0b: lock Thread 1: EXC_BAD_ACCESS (code=2, address=0x20)
0x1e07e0c: xaddl %ecx, 32(%eax)
0x1e07e10: incl %ecx
0x1e07e11: testl %ecx, %ecx
0x1e07e13: jg 0x1e07e22 ; dispatch_semaphore_signal + 32
0x1e07e15: cmpl $2147483648, %ecx
0x1e07e1b: je 0x1e07e25 ; dispatch_semaphore_signal + 35
0x1e07e1d: jmp 0x1e081c1 ; _dispatch_semaphore_signal_slow
0x1e07e22: xorl %eax, %eax
0x1e07e24: ret
0x1e07e25: ud2
을 . UserTrack.m에서
일부 방법 :
-(void)startTracking
{
if(_isTracking)
return;
// Clear old data
[_locations removeAllObjects];
[_lm startUpdatingLocation];
_isTracking = true;
NSLog(@"is tracking!");
}
// Stop tracking GPS coordinates
-(void)stopTracking
{
if (!_isTracking)
return;
if(_lm != nil)
[_lm stopUpdatingLocation];
_isTracking = false;
NSLog(@"STOPPED TRACKING");
}
-(id)init
{
if(self = [super init])
{
_isTracking = false;
_locations = [[NSMutableArray alloc] init];
_lm = [[CLLocationManager alloc] init];
_lm.delegate = self;
_lm.distanceFilter = kCLDistanceFilterNone; // whenever we move
_lm.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
}
return self;
}
는 또한 같은 클래스에서 구현 : 호출되지 않는
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
// Callback: new GPS coordinate available
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
을 ...이 스레드 문제인가? 왜 이상한 세마포어 오류가 발생합니까? 나는 "BPTest"-class에서 completly 테스트를 이동하려고 만 테스트하는 빠른 "해키"방법 ... 등
int main(int argc, char *argv[])
{
@autoreleasepool
{
// TODO: remove this class
BPTest * bt = [[BPTest alloc] init];
[bt runTests];
// Above must be removed and the location test inserted directly here...
return UIApplicationMain(argc, argv, nil, NSStringFromClass([BPAppDelegate class]));
}
}
과 :
[NSThread sleepForTimeInterval : 30]을 왜 호출하고 있습니까? 또한 대의원을 정 했니? – sosborn
시뮬레이터를 사용하여 손으로 시뮬레이션 좌표를 입력 할 시간이 있습니다. 좌표가 입력되면 프로그램은이를 기록한 콜백을 호출해야하며 모두 완료되면 거리 계산이 수행됩니다. delegate는 init-method에서 설정됩니다. – hirre
시뮬레이터가 좌표를 제공한다는 것을 알고 계셨습니까? 당신은 단지 그들을 켜야 만합니다. 나는 그것이 당신의 문제를 해결하는지보기 위해 노력하는 것이 좋습니다. – sosborn