Whereami App showing one warning in iOS 6.1


#1

When i run the whereami app in ios 6.1 (xcode 4.6) for developers beta version

In WhereamiViewController.m file

  • (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
    fromLocation:(CLLocation *)oldLocation
    // its shown that this method is deprecated.
    The new method is

  • (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations

Can you please tell me how to write the codes using this method. Because
"NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];"
is not recognised inside this method.

Thank You


#2

[quote]- blocationManager:(CLLocationManager *)manager didUpdateLocations:[color=#FF0000](NSArray *)locations[/color][/b]

Can you please tell me how to write the codes using this method. Because
"NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];"
is not recognised inside this method.[/quote]
You should go and read the CLLocationManager Class Reference and find out if you can find something inside the locations array, from which you can compute the newLocation.


#3

I am stumped as well, can someone please update the sample code?


#4

[self foundLocation:locations.lastObject];
that appears to work, try it and let me know if you agree.
Thanks


#5

yes i have tried inserting [[[locations lastObject] timeStamp] timeIntervalSinceNow]; and it still doesnt work even though i got it to print the last time using [locations lastObject] it seems it wont work and i havent seen anything online and the authors seem not to care that it doesnt work


#6

ive found a way to make it work but right now it wont stop updating ill check back with you after i fix it hopefully


#7

i am thinking the made is so it wont repeat duplicates with in a certain amount of time i think you might had to override timestamp for you to be able to create your own maybe i am wrong though cause i believe thats what causing the problem becausei havent been able to think of a way to write the last code i looked in the api documentation an everything my knowledge its that vast but still cant figure it out


#8

i appeared to have found a solution with my novice self lol pretty rewarding but i made a post about hope it helps guys


#9

Hey there -

The API for this in 6.1 is slightly different. Here’s how I did it (Owen the instructor said it was a reasonable approach):

gist.github.com/kwhinnery/5337321

HTH,
-Kevin


#10

Try the following:

NSArray is an array of (id)'s and so lastObject returns an (id), so we coerce it into a CLLocation *.


#11

[quote=“ibex10”][quote]- blocationManager:(CLLocationManager *)manager didUpdateLocations:[color=#FF0000](NSArray *)locations[/color][/b]

Can you please tell me how to write the codes using this method. Because
"NSTimeInterval t = [[newLocation timestamp] timeIntervalSinceNow];"
is not recognised inside this method.[/quote]
You should go and read the CLLocationManager Class Reference and find out if you can find something inside the locations array, from which you can compute the newLocation.[/quote]

This will be the solution:-

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ //CLLocationManagerDelegate method implementation
    

//    NSTimeInterval t0=[[locations lastObject] timeIntervalSinceNow];
    
    NSLog(@"%@",(CLLocation *)[locations lastObject]);
    NSTimeInterval t= [[(CLLocation *)[locations lastObject] timestamp] timeIntervalSinceNow];
    
    if (t<-180) {
        return;
    }
    
    [self foundLocation:[locations lastObject]];
    
}

In your code, you did [locations lastObject] timestamp] . [locations lastObject] returns id which can receive any kind of message. But id is not automatically upcast to CLLocation. If you had used [newLocation timestamp] message would return (NSDate *) object which can further receive timeIntervalSinceNow message. The problem is that timestamp method in this case doesn’t return (NSDate *) object. It returns a typedef struct- NSTimeInterval and typedefs can’t receive any kind of messages.

In the line— [self foundLocation:[locations lastObject]]; the parameter of the particular of CLLocation type which accepts id type easily. So variable assignment does an automatic upcast for you.