이제 코드가 작동하지만 여전히 작업이 필요합니다. 내가 얻는 가치는 "끈적"하고, 안정적이지 않다. (자기 북쪽으로 되돌아 가려고 할 때마다 조금 움직이는 것 같다.) 나는 그 장치를 조금씩 흔드는 것이 필요하다. 값 ..이 코드를 사용하여 자기 북쪽에서 장치의 편차를 읽을 수없는 이유는 무엇입니까?
Game.h
#import <Foundation/Foundation.h>
#import "CoreLocation.h"
@interface Game : NSObject
<CLLocationManagerDelegate>
@property BOOL stopButtonPressed;
-(void) play;
@end
Game.m
@implementation Game
- (id) init
{
self = [super init];
self.stopButtonPressed = NO;
CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
return self;
}
-(void) play
{
[locationManager startUpdatingHeading];
while(!self.stopButtonPressed)
{
double degrees = locationManager.heading.magneticHeading;
int degreesRounded = (int)degrees;
NSLog(@"Degrees : %i", degreesRounded);
}
}
@end
MyViewController.m
@interface MyViewController()
{
Game *game;
}
@end
@implementation MyViewController
-(void) viewDidLoad
{
game = [[Game alloc] init];
}
- (IBAction)playPressed:(UIButton *)sender
{
[game performSelectorInBackground:@selector(play) withObject:nil];
}
- (IBAction)stopPressed:(UIButton *)sender
{
game.stopButtonPressed = YES;
}
@end
은 '아무튼 메인 스레드를 막고있는 것처럼 보입니다. 콘솔에서 "제목 사용 가능"을 얻은 다음 "학위 : 0.000"을 계속 가져옵니다. –
무한 루프에서 오른쪽으로 이동합니다. 고정되어 있지 않습니다. –
나는 '(game performSelectorInBackground : @selector (play) withObject : nil];' –