2012-02-13 7 views
2

내 장치에 CMMotionManager을 사용하고 있으므로 장치 모션 정보를 얻을 수 있습니다. 나는이 두 가지 방법이 있습니다멀티 태스킹을 지원하는 CMMotionManager

- (void)startDeviceMotion { 
    motionManager = [[CMMotionManager alloc] init]; 
    motionManager.showsDeviceMovementDisplay = YES; 
    motionManager.deviceMotionUpdateInterval = 1.0/120.0; 
    [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical]; 
} 

두 번째로는 다음과 같은 경우 응용 프로그램이 시작될 때 응용 프로그램이 각각 완료

- (void)stopDeviceMotion { 
    [motionManager stopDeviceMotionUpdates]; 
    [motionManager release]; 
    motionManager = nil; 
} 

는 그들은 시작하고 있습니다. 내 문제는 이제 멀티 태스킹입니다. 배경으로 문제가 생겨 다시 전경으로 가져 오면 [CMMotionManager retain] 메시지가 할당 해제 된 인스턴스로 전송되고 있다는 메시지가 나타납니다 (NSZombie 활성화).

내 문제는 어디에 있습니까?

감사합니다.

답변

2

Jonathan's suggestion here을 사용해보세요. 기본적으로 CMMotionManager의 인스턴스가 하나만 생성되도록하려면 motionManager를 AppDelegate에 넣고이 방법으로 모션 관리자를 사용하려는 모든 곳에서이 메서드로 검색하십시오.

-(CMMotionManager *)motionManager 
{ 
    CMMotionManager *motionManager = nil; 
    id appDelegate = [UIApplication sharedApplication].delegate; 
    if ([appDelegate respondsToSelector:@selector(motionManager)]) { 
    motionManager = [appDelegate motionManager]; 
} 
return motionManager; 
} 

이 기능이 작동하는지 알려주세요.

+0

그것은 나를 위해 절대적으로 효과가 있습니다! 나는 같은 문제가있다. 오늘 나를 위해 고칠 많은 시간을 낭비한다. 정말 고맙습니다! : D – Sakares

+0

당신은 대단히 환영합니다. 늦은 응답에 대한 죄송합니다 :) – Q8i

관련 문제