다음 코드는 사용자 위치를 추적하고 사용자가 JSON 파일의 지정된 이벤트 중 하나에있는 경우 현재 사용자 위치의 long 및 lat를 long과 일치시킴으로써 탐지합니다 오늘 이벤트의 위도 + 이벤트 시작 시간이 현재 iPhone 시간과 같을 때 다음 지침을 수행 한 다음 NSTimer를 5 분 동안 실행하고 5 분 후이 메서드를 onTick() 메서드를 호출하면 시작 시간 그리고 5 분이 지나면 현재 시간은 5 분을 경과하고, 여전히 5 분 이상 지속되면이 이벤트를 참석 한 것으로 설정하십시오. 것은 나의 iPhone에 그것을 시험 할 때 작동한다 그러나 나가 사용자가 그 시간 인 단지 존재하는 사건을 위해 일하고 싶었더라도 5 분 이상 시간 간격을 가진 모든 사건을 위해 !! 일어나고있는 무엇이 솔루션 .. 임 정말 혼동 될 수 있다는 이유 누군가가 여기에 NSTimer 위치 추적 (업데이트)
내 코드입니다 .. 나를 위해 설명 plzzz 수 있습니다.h file
@property (nonatomic, strong) Event *currentEvent;
@property (nonatomic, strong) CLLocation *currentEventLocation;
@property (nonatomic, strong) NSDate *arrivalDate;
@property (nonatomic, strong) CLLocation *currentLocation;
@property (nonatomic, strong) CLLocation *theNewLocation;
.m file
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
self.currentLocation = [locations lastObject];
if (self.currentEvent) {
if ([self.arrivalDate timeIntervalSinceNow]<60*3) {
if ([self.currentEventLocation distanceFromLocation:self.theNewLocation]<100) {
[self.currentEvent setHasATTENDED:[NSNumber numberWithBool:TRUE]];
}
}
}
self.currentLocation = self.theNewLocation;
for (Event *event in [self loadTodaysEvents]) {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
NSDate *currentTime = [NSDate date];
[dateFormatter setDateFormat:@"HH:mm"];
NSString *resultString = [dateFormatter stringFromDate:currentTime];
NSString *eventStartTime = event.startingTime;
// distance
CLLocationDegrees lat = [event.lat doubleValue];
CLLocationDegrees lon = [event.longi doubleValue];
CLLocation *evLocation = [[CLLocation alloc] initWithLatitude:lat longitude:lon];
double distance = [evLocation distanceFromLocation:self.theNewLocation];
// CLOSE !
if (distance <= 100 && [resultString isEqualToString:eventStartTime]) {
self.arrivalDate = currentTime;
self.currentEvent = event;
self.currentEventLocation = evLocation;
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 180.0
target: self
selector: @selector(onTick:)
userInfo: nil
repeats: NO];
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:timer forMode: NSDefaultRunLoopMode];
}
}
}
- (void)onTick:(NSTimer *)timer
{
[self locationManager:nil didUpdateLocations:@[self.currentLocation]];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
}
, 당신은 runloop에 광고가에 필요 없어요! –
[NSDate date]를 NSString으로 변환하고 NSDate로 되 돌리는 이유는 무엇입니까? –
나는이 선이 의미가 있다고 생각하지 않는다! 이 이벤트 시작 시간이 현재 시간과 같은지 확인하고 싶은지 확인하십시오! [resultString isEqualToString : eventStartTime] –