मैं रममोबाइल ढांचे का उपयोग करके काम करने के लिए आईफोन का कंपास प्राप्त करने की कोशिश कर रहा हूं। मैंने पहले से ही रमोबाइल भाग किया है, एक काम करने वाला रैपर बनाया है जो आईफोन पर देशी तरीकों को कॉल करता है, लेकिन मैं घटनाओं को काम करने के लिए प्रबंधित नहीं कर सकता।CLLocationManager प्रतिनिधि प्रारंभिकरण के बाद काम नहीं कर रहे हैं
Locationmanager.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface locationController : NSObject <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) CLLocationManager *locationManager;
- (id)init;
- (void)dealloc;
@end
Locationmanager.m
#import "Locationmanager.h"
#include "ruby/ext/rho/rhoruby.h"
//store the values
double gx, gy, gz, gth;
//init location
locationController *lc;
@implementation locationController
@synthesize locationManager;
- (id)init {
if (self = [super init]) {
self.locationManager = [[CLLocationManager alloc] init];
NSLog(@"%@", [CLLocationManager headingAvailable]? @"\n\nHeading available!\n" : @"\n\nNo heading..\n");
NSLog(@"%@", [CLLocationManager locationServicesEnabled]? @"\n\nLocation available!\n" : @"\n\nNo location..\n");
// check if the hardware has a compass
if ([CLLocationManager headingAvailable] == NO) {
// No compass is available. This application cannot function without a compass,
// so a dialog will be displayed and no magnetic data will be measured.
locationManager = nil;
UIAlertView *noCompassAlert = [[UIAlertView alloc] initWithTitle:@"No Compass!" message:@"This device does not have the ability to measure magnetic fields." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[noCompassAlert show];
[noCompassAlert release];
NSLog(@"\n***** ERROR *****\n No compass found !!!");
} else {
// setup delegate callbacks
locationManager.delegate = self;
// heading service configuration
locationManager.headingFilter = kCLHeadingFilterNone;
// location service configuration
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
//start location services
[locationManager startUpdatingLocation];
// start the compass
[locationManager startUpdatingHeading];
}
return self;
}
}
- (void)dealloc {
[super dealloc];
// Stop the compass
[locationManager stopUpdatingHeading];
[locationManager release];
}
// This delegate method is invoked when the location manager has heading data.
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)heading {
NSLog(@"\n\n***** New magnetic heading *****\n %f\n", heading.magneticHeading);
NSLog(@"\n\n***** New true heading *****\n %f\n", heading.trueHeading);
gx = heading.x;
gy = heading.y;
gz = heading.z;
gth = heading.trueHeading;
}
// This delegate method is invoked when the location managed encounters an error condition.
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
if ([error code] == kCLErrorDenied) {
// This error indicates that the user has denied the application's request to use location services.
NSLog(@"\n ***** ERROR *****\n Location not allowed!");
[locationManager stopUpdatingHeading];
} else if ([error code] == kCLErrorHeadingFailure) {
NSLog(@"\n ***** ERROR *****\n Magnetic interference or something!");
}
}
@end
//ruby wrappers
void locationmanager_init(void) {
// make sure we can only start this method once
static bool started = false;
if(!started) {
// Initialize the Objective C accelerometer class.
lc = [[locationController alloc] init];
started = true;
}
}
void locationmanager_get_heading(double *x, double *y, double *z, double *th) {
NSLog(@"\n ***** DEBUGGER *****\n Getting heading x: %f, y: %f, z: %f, heading: %f", gx, gy, gz, gth);
*x = gx;
*y = gy;
*z = gz;
*th = gth;
}
मैं एक iPhone 4 पर कोड चल रहा हूँ आईओएस 5.1 के साथ, कंसोल में मैं init की डिबग संदेश देख सकते हैं, लेकिन मैंने didUpdateHeading प्रतिनिधि का एक डीबग संदेश कभी नहीं देखा। किसी को भी एक सुराग मिला जो मुझे याद आया?
अद्यतन
मुझे लगता है मैं यह काम कर पाने के लिए एक पृष्ठभूमि सूत्र में मेरी कोड चलाने की आवश्यकता है। वर्तमान में locationmanager_init प्रारंभ होता है + कोड छोड़ देता है, क्योंकि यह सक्रिय नहीं है और घटनाओं को निकाल दिया नहीं जाता है। किसी को भी इसे सक्रिय रखने के लिए पृष्ठभूमि में इसे शुरू करने का एक आसान समाधान मिला है?
अद्यतन 2
आईडी वापस लौटाया, self = [super init]
और अभी भी कोई ठीक :(
GitHub code initializes इस्तेमाल किया,
https://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html – fibnochi
मैं के साथ और में प्रतिनिधियों को परिभाषित करने के बिना इसे करने की कोशिश पर एक नज़र डालें एच फाइल। NSObject के बजाय UIViewController का भी उपयोग किया गया, जैसा कि यह ऐप्पल के टेस्लामीटर उदाहरण में किया गया है, अभी भी कोई प्रगति नहीं है :( – Vikko
मुझे अपना कोड ईमेल करें। – fibnochi