Coder Social home page Coder Social logo

vicpenap / vpplocation Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 5.0 204 KB

VPPLocation Library for iOS simplifies the task of retrieving the user location and geocoder info about it.

Home Page: http://vicpenap.github.com/VPPLocation

License: Other

Objective-C 98.71% Ruby 1.29%

vpplocation's People

Contributors

exister avatar vicpenap avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vpplocation's Issues

VPPLocation cause crash at runtime for iOS 4.x

Hi.
I've used cocoapods to get library.
I have subject issue at application start up in release mode.
Here one string from crash log:
Symbol not found: _OBJC_CLASS_$_CLGeocoder

Here is temporary solution for those who use cocoapods to work with library:
Add these lines to your pods .pch file if you want to run library on iOS 4.x

#import <Availability.h>
#undef __IPHONE_5_0

some extra retain on delegate results in my mapvc not deallocating

I have an existing class MyCLController
I implemented your delegate call backs and tried to swap it in.
with my class below when my mapvc gets popped - it successfully shuts down core location and saves battery after about 30 seconds.

When I swap in your class, my mapvc is still being retained - it never gets deallocated.
I can remove the delegate in view will disappear and re-add it on viewwillappear - but I think you need to use an assign property instead for your delegates.

Because you are wrapping the delegates in an array - you would need to rethink the existing code. You have to consider the limitations of the existing class. It's going to cause memory problems.

you have a few options -

weak selfs / blocks. Use one delegate only.

when you add objects here - it is going to retain them.
geocoderDelegates_ = [[NSMutableArray alloc] init];

The goal I propose is to have the singleton shutdown when it's not needed.

or one trick shot you have is to try to tear down the class - but at what point should this be done? This is not a good solution. Also your dealloc method will never get called using the synthesise singleton call

-(void)tearDown{
remove all delegates
deallocate
}

 File: MyCLController.h
 Abstract: Singleton class used to talk to CoreLocation and send results back to
 the app's view controllers.

 Version: 1.1
 */
#import <CoreLocation/CoreLocation.h>

// This protocol is used to send the text for location updates back to another view controller
@protocol MyCLControllerDelegate <NSObject>
@required
-(void)newLocationUpdate:(CLLocation *)newLocation;
-(void)newLocationError:(NSString *)text;
@end


// Class definition
@interface MyCLController : NSObject <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
    id delegate;
    BOOL updating;
}

@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic,assign) id <MyCLControllerDelegate> delegate;
@property BOOL updating;

-(void)startUpdatingLocation;
-(void)stopUpdatingLocation;

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

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error;

+ (MyCLController *)sharedInstance;

@end





#import "MyCLController.h"

// This is a singleton class, see below
static MyCLController *sharedCLDelegate = nil;

@implementation MyCLController

@synthesize delegate, locationManager, updating;

- (id) init {
    self = [super init];
    if (self != nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // Tells the location manager to send updates to this object
    }
    return self;
}

-(void)startUpdatingLocation {
    self.updating = YES;
    [self.locationManager startUpdatingLocation];
}

-(void)stopUpdatingLocation {
    self.updating = NO;
    [self.locationManager stopUpdatingLocation];
}

// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{

    // Negative accuracy means an invalid or unavailable measurement
    if (signbit(newLocation.horizontalAccuracy)) {
        return;
    }

    // If location timestamp was ages ago, it's a cached one; ignore it
    NSTimeInterval howRecent = [newLocation.timestamp timeIntervalSinceNow];
    if (abs(howRecent) > 5.0) {
        return;
    }

    [self.delegate newLocationUpdate:newLocation];
}


// Called when there is an error getting the location
- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    NSMutableString *errorString = [[[NSMutableString alloc] init] autorelease];

    if ([error domain] == kCLErrorDomain) {

        // We handle CoreLocation-related errors here

        switch ([error code]) {
                // This error code is usually returned whenever user taps "Don't Allow" in response to
                // being told your app wants to access the current location. Once this happens, you cannot
                // attempt to get the location again until the app has quit and relaunched.
                //
                // "Don't Allow" on two successive app launches is the same as saying "never allow". The user
                // can reset this for all apps by going to Settings > General > Reset > Reset Location Warnings.
                //
            case kCLErrorDenied:
                [self stopUpdatingLocation];
                [self.delegate newLocationError:NSLocalizedString(@"NeedLocationKey", @"UGlii needs your location.")];
                break;

                // This error code is usually returned whenever the device has no data or WiFi connectivity,
                // or when the location cannot be determined for some other reason.
                //
                // CoreLocation will keep trying, so you can keep waiting, or prompt the user.
                //
            case kCLErrorLocationUnknown:
                [errorString appendFormat:@"%@\n", NSLocalizedString(@"LocationUnknown", nil)];
                break;

                // We shouldn't ever get an unknown error code, but just in case...
                //
            default:
                [errorString appendFormat:@"%@ %d\n", NSLocalizedString(@"GenericLocationError", nil), [error code]];
                break;
        }
    } else {
        // We handle all non-CoreLocation errors here
        // (we depend on localizedDescription for localization)
        [errorString appendFormat:@"Error domain: \"%@\"  Error code: %d\n", [error domain], [error code]];
        [errorString appendFormat:@"Description: \"%@\"\n", [error localizedDescription]];
    }

    self.updating = NO;

    // Send the update to our delegate
    // [self.delegate newLocationUpdate:errorString];
}

#pragma mark ---- singleton object methods ----

// See "Creating a Singleton Instance" in the Cocoa Fundamentals Guide for more info

+ (MyCLController *)sharedInstance {
    @synchronized(self) {
        if (sharedCLDelegate == nil) {
            [[self alloc] init]; // assignment not done here
        }
    }
    return sharedCLDelegate;
}

+ (id)allocWithZone:(NSZone *)zone {
    @synchronized(self) {
        if (sharedCLDelegate == nil) {
            sharedCLDelegate = [super allocWithZone:zone];
            return sharedCLDelegate;  // assignment and return on first allocation
        }
    }
    return nil; // on subsequent allocation attempts return nil
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}

- (id)retain {
    return self;
}

- (unsigned)retainCount {
    return UINT_MAX;  // denotes an object that cannot be released
}

- (void)release {
    //do nothing
}

- (id)autorelease {
    return self;
}

@end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.