How can ios detect gps tampering on xcode, it comes with “simulate location” on xcode, is there a way to detect gps tampering caused by it?
The debug output area of xcode has a button called "simulate location" which allows you to simulate the location of different countries, and when you use CLLocation to get the location it will output the location of the country selected by the simulator.
CLLocationManager *manager = [[CLLocationManager alloc] init];
[CLLocationManager authorizationStatus];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager requestAlwaysAuthorization];
[manager startUpdatingLocation];
if( [CLLocationManager locationServicesEnabled] ) {
CLLocation *location = [manager location]; //maybe other country
NSLog(#"%#", location);
}
Related
My app collects location and accelerometer information, and continues to do so in the background if the user requests it. The accelerometer information is collected at about 100 Hz, and it is critical that it be collected at a high rate. The app has worked fine under older versions of iOS, but is failing under iOS 10. I'm looking for a way to continue collecting accelerometer information while in the background.
The method used is similar to that in Receive accelerometer updates in background using CoreMotion framework. I start the location manager:
latitude = 0.0;
longitude = 0.0;
altitude = 0.0;
horizontalAccuracy = -1.0;
verticalAccuracy = -1.0;
if (locationManager == nil && [CLLocationManager locationServicesEnabled]) {
self.locationManager = [[CLLocationManager alloc] init];
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if (status == kCLAuthorizationStatusNotDetermined) {
[locationManager requestWhenInUseAuthorization];
}
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.pausesLocationUpdatesAutomatically = NO;
[locationManager startUpdatingLocation];
}
I implement locationManager:didUpdateLocations:
- (void) locationManager: (CLLocationManager *) manager didUpdateLocations: (NSArray *) locations {
printf("locationManager:didUpdateLocations:\n");
CLLocation *location = locations.lastObject;
latitude = location.coordinate.latitude;
longitude = location.coordinate.longitude;
altitude = location.altitude;
horizontalAccuracy = location.horizontalAccuracy;
verticalAccuracy = location.verticalAccuracy;
}
I start the motion manager:
motionManager = [[CMMotionManager alloc] init];
motionManager.accelerometerUpdateInterval = 1.f/trialFrequency;
[[NSOperationQueue mainQueue] setMaxConcurrentOperationCount: 10];
[motionManager startAccelerometerUpdatesToQueue: [NSOperationQueue mainQueue]
withHandler: ^(CMAccelerometerData *accelerometerData, NSError *error) {
// Flag any error.
if (error) {
NSLog(#"error getting accelerometer update: %#", error);
}
<<<process data>>>
}
];
TARGETS, Capabilities, Background Modes, Location updates is checked.
Under iOS 9 and previous, the motion information is recorded at a rate of around 100 Hz with no problem, but under iOS 10, the motion information stops as soon as the app enters the background.
Is there any way to get the motion information to continue in the background under iOS 10?
Beginning with iOS 9, there is a new call required to enable background processing of location events. It can be used to turn background processing on and off, but defaults to off, so it must be set manually to restore background processing in iOS 8 and prior code.
Add this line when setting up the location manager to allow background processing:
locationManager.allowsBackgroundLocationUpdates = YES;
I am developing an application to find a beacon. But i have a problem that is i can only find a beacon which I have defined in code but i want to find beacon dynamically which i dont know the UUID. And is that possible to find a beacon without location service? Here is my just code i do not get any error.. I just want to access region without location service ON..
NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:#"D57092AC-DFAA-446C-8EF3-C81AA22815B5"];
NSString *regionIdentifier = #"us.iBeaconModules";
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID identifier:regionIdentifier];
self.locationManager = [[CLLocationManager alloc] init];
if([self.locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
[self.locationManager startMonitoringForRegion:beaconRegion];
[self.locationManager startRangingBeaconsInRegion:beaconRegion];
No, you can not use iBeacons without the location services.
The reason behind is this is probably has to do with privacy, since with iBeacons you can track someones location. Thus if the user turned of the location services it means they do not want you app to track their location.
You could of course use the bluetooth stack to detect you iBeacons but to my knowledge you will have to pair with the beacon first before you can detect its presence.
In my current project.
I need user's location at every 50 meter user move.
So Basically After open application every 50 meter change I need user location for call web service in Objective c. Also i want same process run when application is in background state.
Thanks in advance
You have to make object of CLLocationManager when application starts and set it's delegate
Add the below code to get user's current location
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
Now add the delegate of CLLocationManagaer that is didUpdateToLocation and add the following code in that.
CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];
if(meters==50)
{
// CALL YOU WEBSERVICE
}
set your location track in
//create location manager object
locationManager = [[CLLocationManager alloc] init];
//there will be a warning from this line of code
[locationManager setDelegate:self];
//and we want it to be as accurate as possible
//regardless of how much time/power it takes
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
//set the amount of metres travelled before location update is made
[locationManager setDistanceFilter:50];
and add
if ([CLLocationManager locationServicesEnabled]) {
[self.locationManager startUpdatingLocation];
}
Update
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = locations.lastObject;
NSLog(#"%#", location.description);
//In here you get all details like
NSLog(#"latitude = %#",location.coordinate.latitude);
NSLog(#"longitude = %#",location.coordinate.longitude);
NSLog(#"altitude = %#",location.altitude);
NSLog(#"horizontalAccuracy = %#",location.horizontalAccuracy);
NSLog(#"verticalAccuracy = %#",location.verticalAccuracy);
NSLog(#"timestamp = %#",location.timestamp);
NSLog(#"speed = %#",location.speed);
NSLog(#"course = %#",location.course);
}
I was asked to code a small app for iOS in Objective C that's supposed to choose the closest object of a user, in a set of coordinates
The plan was to load the coordinates of the user only once, when the application loads for the first time.
Here's my current code :
(void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.headingFilter = 1;
self.locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager startUpdatingLocation];
self.userLat = self.locationManager.location.coordinate.latitude;
self.userLon = self.locationManager.location.coordinate.longitude;
NSLog(#" ----------------------------- ");
NSLog(#"User lat : %lf", self.userLat);
NSLog(#"User lon : %lf", self.userLon);
NSLog(#" ----------------------------- ");
}
I don't have a Apple iOS developper program, so I'm stuck with the iOS simulator from xCode.
I try to set some custom coordinates in the iOS simulator through debug, like this :
When i execute the app (obviously after setting coordinates), the log has userLat and userLon to 0.00..
Apr 6 03:16:20 Locals-Mac.local app[5683]: -----------------------------
Apr 6 03:16:20 Locals-Mac.local app[5683]: User lat : 0.000000
Apr 6 03:16:20 Locals-Mac.local app[5683]: User lon : 0.000000
Apr 6 03:16:20 Locals-Mac.local app[5683]: -----------------------------
I remember hearing somewhere that the iOS simulator don't work with the CoreLocation library (It might be right or wrong, i wouldn't know).
Is it the reason the lat/lon values are 0?
If the reason is indeed the iOS simulator, does this code give user current location?
Thanks in advance!
Edit :
With the answer and comments, i'm now using the didUpdateLocations callback function :
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *location = [locations lastObject];
self.userLat = location.coordinate.latitude;
self.userLon = location.coordinate.longitude;
NSLog(#" ----------------------------- ");
NSLog(#"User lat : %lf", self.userLat);
NSLog(#"User lon : %lf", self.userLon);
NSLog(#" ----------------------------- ");
}
I ask xCode to simulate my position to London with the Scheme option that follows :
My new load function :
-(void)viewDidLoad {
[super viewDidLoad];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.headingFilter = 1;
self.locationManager.delegate = self;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
[self.locationManager requestWhenInUseAuthorization];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
[self.locationManager startUpdatingLocation];
}
This code still doesn't print the NSLog that was put in the location callback function. Did i miss something?
The location manager doesn't instantly have the user's location when you start updating it. If you check the location property right after calling startUpdatingLocation it is usually going to be nil unless some other app was recently updating it. You need to implement the locationManager:didUpdateLocations: delegate method which will be called once it has a location.
You also need to check and possibly request for location permissions.
So it works when I'm on WiFi. But on 4G, it only works if I had been on Wifi and it already has the location. A lot of times without WiFi, the phone will say it's using my location but its not updating the label nor is it uploading the coordinates to the server. Here's the code:
- (void)viewDidLoad {
[super viewDidLoad];
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if ([self->locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]) {
[self->locationManager requestWhenInUseAuthorization];
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *newLocation = [locations lastObject];
NSString *locationLat = [NSString stringWithFormat:#"%.8f", newLocation.coordinate.latitude];
NSString *locationLong = [NSString stringWithFormat:#"%.8f", newLocation.coordinate.longitude];
latLongLabel.text = [NSString stringWithFormat:#"Lat: %# - Long%#",locationLat,locationLong];
[self postLocation:locationLat secondArg:locationLong];
}
- (void)postLocation: (NSString *)latitudeString secondArg:(NSString *)longitudeString {
//POST COORDINATES TO MY SERVER
}
- (IBAction)startUpdating:(id)sender {
[locationManager startUpdatingLocation];
}
My suspicion is that when you are on 4G, the location updates still work fine (although wifi triangulation makes them a bit more precise but only Apple knows how, as the implementation is private), BUT there might be an issue sending those values to the server quickly or reliably enough via 4G connection. (for example in London it is slow as hell with so many people around)
You might narrow the debugging by simply logging the location update directly to some UIlabel on your view, and not going through server infrastructure.
AS a last resort I would make sure
that you set your CLActivityType property to CLActivityTypeFitness
and pausesLocationUpdatesAutomatically is set to NO.