2011-09-01 62 views
1

我面臨這個錯誤,我想知道我錯在哪裏。CoreLocation 0x34456f78 - [CLLocationManager onClientEventRegistered:] + 384

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0x80000008 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 libobjc.A.dylib 0x34499c98 objc_msgSend + 16 
1 CoreLocation  0x34456f78 -[CLLocationManager onClientEventRegistered:] + 384 
2 CoreLocation  0x34457f42 -[CLLocationManager onClientEvent:supportInfo:] + 46 
3 CoreLocation  0x34455a64 OnClientEvent + 16 
4 CoreLocation  0x3445178a CLClientInvokeCallback(__CLClient*, CLClientEvent, __CFDictionary const*) + 46 
5 CoreLocation     0x344528cc CLClientHandleDaemonDataRegistration(__CLClient*, CLDaemonCommToClientRegistration const*, __CFDictionary const*) + 700 
6 CoreLocation     0x34453d50 CLClientHandleDaemonData(__CFMessagePort*, long, __CFData const*, void*) + 220 
7 CoreFoundation     0x3094e706 __CFMessagePortPerform + 242 
8 CoreFoundation     0x30957a90 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20 
9 CoreFoundation     0x30959838 __CFRunLoopDoSource1 + 160 
10 CoreFoundation     0x3095a606 __CFRunLoopRun + 514 
11 CoreFoundation     0x308eaebc CFRunLoopRunSpecific + 224 
12 CoreFoundation     0x308eadc4 CFRunLoopRunInMode + 52 
13 GraphicsServices    0x30269418 GSEventRunModal + 108 
14 GraphicsServices    0x302694c4 GSEventRun + 56 
15 UIKit       0x30a10d62 -[UIApplication _run] + 398 
16 UIKit       0x30a0e800 UIApplicationMain + 664 
17 ProjectOne      0x00002918 main (main.m:14) 
18 ProjectOne      0x000028cc start + 32 

我的代碼:

Start Location : 
-(void)startLocationTracing 
{    
self.TlocationManager = [[CLLocationManager alloc] init];//allocate memeory to locationmanager 
self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as possible 
self.TlocationManager.distanceFilter = kCLLocationAccuracyBest;       
self.TlocationManager.delegate = self;  
[self.TlocationManager startUpdatingLocation]; 
} 

Delegate Method : 

- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation 
{ 


lat = [NSString stringWithFormat:@"%3.5f", 
      newLocation.coordinate.latitude]; 
lng = [NSString stringWithFormat:@"%3.5f", 
      newLocation.coordinate.longitude]; 



CLLocation *loc_old = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude]; 
CLLocation *loc_new = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude]; 

//get the current distance from the old distance 
CLLocationDistance dist = [loc_old distanceFromLocation:loc_new]; 

// test the age of the location measurement to determine if the measurement is cached 
// in most cases you will not want to rely on cached measurement 
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow]; 
if (locationAge > 5.0) 
{ 

    NSLog(@":::::::Location age is greate then 5.0 ::::::::"); 
    [loc_old release]; 
    [loc_new release]; 
    return; 

} 
float dist_ = (float)dist;//distance in float 
NSLog(@"%f", dist_); 

[loc_old release]; 
[loc_new release]; 



NSString *str_LastLat = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"LastLat"]]; 
NSString *str_LastLong = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults] valueForKey:@"LastLong"]]; 


if(([str_LastLat isEqualToString:lat]) && ([str_LastLong isEqualToString:lng])) 
{ 
    //if same lat and long arrives then do not save in the database 

    NSLog(@"old and new location are same"); 

} 
else 
{ 

    if((newLocation.horizontalAccuracy > 0) || (newLocation.verticalAccuracy > 0)){ 


     [self stopTracingLocations];//to stop location services after the data is sent to 

     objGlobal = [[Global alloc] init];     
     [objGlobal postLocateValue:lat :lng type:@"TRACING"]; // WCF HIT 
     [objGlobal release]; 

    } 

} 
} 



Stop Location : 

-(void)stopTracingLocations 
{ 

[self.TlocationManager stopUpdatingLocation]; 
self.TlocationManager.delegate = nil;  
if(self.TlocationManager){ 
    [self.TlocationManager release]; 
} 

} 

回答

2

那麼它可能是由於你正在泄漏/ incorectly assining」

-(void)startLocationTracing {    
    self.TlocationManager = [[[CLLocationManager alloc] init] autorelease];//allocate memeory to locationmanager 
    self.TlocationManager.desiredAccuracy = kCLLocationAccuracyBest; //Be as accurate as possible 
    self.TlocationManager.distanceFilter = kCLLocationAccuracyBest;       
    self.TlocationManager.delegate = self;  
    [self.TlocationManager startUpdatingLocation]; 
} 

-(void)stopTracingLocations { 
    [self.TlocationManager stopUpdatingLocation]; 
    self.TlocationManager.delegate = nil;  
    self.TlocationManager = nil; 
} 
0

我有同樣的錯誤事實證明,我是。分配位置管理器兩次,你可能想看看你是否在這樣做。

它發生在我身上因爲我有一個子類在init上調用超級方法。 super.init分配了一個位置管理器。我忘了這一點,並在分類課程中再次分配。