LocationSpoofer is an iOS library for spoofing / mocking location, without changing any of your existing CoreLocation code.
LocationSpoofer is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LocationSpoofer'
To spoof your current location, simply set the location
property on LocationSpoofer
to a non-nil value:
/// Swift
let alcatraz = CLLocation(latitude: 37.825944, longitude: -122.422398)
LocationSpoofer.shared.location = alcatraz
/// Objective-C
CLLocation *alcatraz = [[CLLocation alloc] initWithLatitude:37.825944 longitude:-122.422398];
[LOSPLocationSpoofer sharedSpoofer].location = alcatraz;
Can't be bothered to look up the exact latitude / longitude? LocationSpoofer has helpers for that:
/// Swift
let address = "1 Telegraph Hill Blvd, San Francisco, CA 94133"
CLLocation.losp_get(withAddress: address) { location, error in
guard let location = location else {
print("Error: \(String(describing: error))")
return
}
LocationSpoofer.shared.location = location
}
/// Objective-C
NSString *address = @"1 Telegraph Hill Blvd, San Francisco, CA 94133";
[CLLocation losp_getLocationWithAddress:address completion:^(CLLocation *location, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
}
[LOSPLocationSpoofer sharedSpoofer].location = location;
}];
LocationSpoofer can spoof trips, i.e. a moving location between a start & end coordinate.
/// Swift
let startAddress = "1150 Lombard St, San Francisco"
let endAddress = "950 Lombard St, San Francisco"
Trip.getWithStartAddress(startAddress, endAddress: endAddress, duration: 10) { trip, error in
guard let trip = trip else {
print("Error: \(String(describing: error))")
return
}
LocationSpoofer.shared.location = trip
}
/// Objective-C
NSString *startAddress = @"1150 Lombard St, San Francisco";
NSString *endAddress = @"950 Lombard St, San Francisco";
[LOSPTrip getTripWithStartAddress:startAddress endAddress:endAddress duration:10 completion:^(LOSPTrip *trip, NSError *error) {
if (error) {
NSLog(@"Error: %@", error);
}
[LOSPLocationSpoofer sharedSpoofer].location = trip;
}];
To disable location spoofing, simply set the location
property on LocationSpoofer
to nil
.
/// Swift
LocationSpoofer.shared.location = nil
/// Objective-C
[LOSPLocationSpoofer sharedSpoofer].location = nil;
LocationSpoofer provides a UI for spoofing location; you may choose to embed this in your app's debug menu if you have one, or via a custom gesture.
/// Swift
let vc = LocationDebugViewController()
present(vc, animated: true)
/// Objective-C
LOSPLocationDebugViewController *vc = [[LOSPLocationDebugViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];
Q: Is LocationSpoofer safe for use in App Store apps? A: Yes! LocationSpoofer does not use any private APIs.
LocationSpoofer is built by the Buglife team, and we hope it saves you some unnecessary driving :)
LocationSpoofer is available under the MIT license. See the LICENSE file for more info.