I'm looking since quite a long time something like a CLLocationManager simulator that would enable me to simulate GPS positions (CLLocation instances that could be retrieved through the CLLocationManager standard delegate mechanism) along a predefined route for instance (with a KML or GPX file
as input, or whatever, but KML would be nice ;).
Something like this is available on the Android emulator and I was wondering if anything like this would exist for the iPhone simulator.
At least this would be great and would speed up testing on the simulator instead of having to drive for real.... :/
If nothing like this exists, what would be your approach to fake such behavior and implement the simulator in such a way that the client is not impacted? (No code change in the delegate of the CLLocationManager for instance.)
Thanks for your links, hints, approaches...
You can't inject the simulator, but you can subclass CoreLocation:
http://code.google.com/p/dlocation/
which subclasses CoreLocationDelegate to return real data on a device and data from a text file when on the simulator.
More info here
Testing CoreLocation on iPhone Simulator
HTH
I think the best approach is to take control from the CLLocationManager by implementing your own category for it and simulate your expected behavior.
I put a description of this approach here :
Testing CoreLocation on iPhone Simulator
Related
i am totally new to iphone and i am trying to create a universal app.
Now I am creating an empty application. According to all tutorials , by checking universal option it should auto create appdelegates for both iphone and ipad.
But all i can see is only one appdelegate . Kindly tell me how can i create both.
Best Regards
Brayden is correct in answering that you almost never need multiple app delegates. All the delegate usually does is handle the moments when the application launches, suspends or terminates. Back in the days when iPhones ran iOS 4.0, and iPads ran iOS 3.2, you might need very different code in the delegate because only iOS 4.0 supported multitasking. Those days are long gone, and your delegate should probably act the same on all devices.
Yes, you sometimes do reach a point where your program must behave differently on iPhone and iPad. Check the idiom at that time and no earlier. Otherwise you're just duplicating code to no purpose.
My most recent app contains almost no special checks for iPhone or iPad. It doesn't even use different XIBs. Instead, my custom views implement layoutSubviews to fill the space available.
That said, once you understand app delegates, maybe you will find a situation where you need them to be different. If you are absolutely certain that your iPhone and iPad behavior will be so wildly divergent, you will need to:
Manually create a new class (preferably inheriting from the existing AppDelegate class)
In your main.m, send the class name of your new delegate to UIApplicationMain depending on the idiom.
See this answer to "Can I create App Delegate file in my project?" to see the changes to main.m.
You really should only be using one AppDelegate for a Universal application. You can use this to share common things that you'll do in there. What exactly do you need multiple AppDelegates for? If you need to do something specific to a device type (i.e. - iPhone or iPad) then you can do a ternary expression like below:
(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? NSLog(#"iPad") : NSLog(#"iPhone");
Im trying to simulate a touch on as UIWebView, how can I programmatically fire a touch event at a certain location? (x and y coordinates)
Just call touchesBegan?
Ideally I'd like to do it without any javascript hack because in the future it may not be a uiwebview
It's not easy to synthesize a touch event on the iPhone: you have to use undisclosed API, so you have a high probability of breaking on every update of the iOS and getting rejecting from Apple.
Here's a link that demonstrates how to synthesize a touch event on the iPhone:
Here's another question on StackOverflow: How to send a touch event to iPhone OS?
It's worth pointing out the KIF framework here. It's intended to run in the simulator but part of the code is simulating touch evens in code. with luck, this will be a good starting point.
https://github.com/square/KIF
Specifically, look at stepToTapViewWithAccessibilityLabel in KIFTestStep.m and the line
[view tapAtPoint:tappablePointInElement];
What you need to do is first create the events you want, and then send them to SpringBoard over the "purple port" eg. mach port. To make them system wide you must forward them to each application over the port. That means you need to actually do what the windowmanager does and looking at which app is active, screen locked, etc.
There are a hand full of private framework APIs that work (IOSurface, GraphicServices, SpringBoardServices, etc.) to get you the pieces you need.
You will have to load these private frameworks at runtime using something like dlopen().
This is 100% possible without jailbreak as of iOS 6.1.4 (current ATM), but you will be loading private frameworks which is not allowed by apple for AppStore ;)
It is possible. Exactly how you mentioned, using GSEvents and sending them to the purple named port of the aplication you are trying to control/simulate. Of course you need KennyTM's GSEvent.h to accomplish this.
I've done this for iOS 4.3, just by changing some of the values that Kenny had (like kGSHandInfoTypeTouchDown), but now I'm trying to do it for iOS 5 and it's not working, till now.
EDIT: It is now working for iOS 5.1.
Without jailbreaking there is no real way to hook a gesture recognizer into all views of the entire system. First off, your app running in the background doesn't have the ability of executing this code.
Im trying to simulate a touch on as UIWebView, how can I programmatically fire a touch event at a certain location? (x and y coordinates)
Just call touchesBegan?
Ideally I'd like to do it without any javascript hack because in the future it may not be a uiwebview
It's not easy to synthesize a touch event on the iPhone: you have to use undisclosed API, so you have a high probability of breaking on every update of the iOS and getting rejecting from Apple.
Here's a link that demonstrates how to synthesize a touch event on the iPhone:
Here's another question on StackOverflow: How to send a touch event to iPhone OS?
It's worth pointing out the KIF framework here. It's intended to run in the simulator but part of the code is simulating touch evens in code. with luck, this will be a good starting point.
https://github.com/square/KIF
Specifically, look at stepToTapViewWithAccessibilityLabel in KIFTestStep.m and the line
[view tapAtPoint:tappablePointInElement];
What you need to do is first create the events you want, and then send them to SpringBoard over the "purple port" eg. mach port. To make them system wide you must forward them to each application over the port. That means you need to actually do what the windowmanager does and looking at which app is active, screen locked, etc.
There are a hand full of private framework APIs that work (IOSurface, GraphicServices, SpringBoardServices, etc.) to get you the pieces you need.
You will have to load these private frameworks at runtime using something like dlopen().
This is 100% possible without jailbreak as of iOS 6.1.4 (current ATM), but you will be loading private frameworks which is not allowed by apple for AppStore ;)
It is possible. Exactly how you mentioned, using GSEvents and sending them to the purple named port of the aplication you are trying to control/simulate. Of course you need KennyTM's GSEvent.h to accomplish this.
I've done this for iOS 4.3, just by changing some of the values that Kenny had (like kGSHandInfoTypeTouchDown), but now I'm trying to do it for iOS 5 and it's not working, till now.
EDIT: It is now working for iOS 5.1.
Without jailbreaking there is no real way to hook a gesture recognizer into all views of the entire system. First off, your app running in the background doesn't have the ability of executing this code.
I am developing an GPS based app. So I was wondering how could I simulate location on iphone simulator?
I downloaded an sample app locateMe. This app does not work on simulator. Does simulator not support location api?
Any help would be appreciated.
Update:
Xcode 4.2 with iOS 5 supports GPS positioning.
Select the Simulator -> Debug -> Location -> Custom Location...
Previous Version
No the simulator does not support it. So for GPS you have to install the application in the device to check it.
Simulator is gonna give you longitude and latitude as the address of Cupertino Where the headquaters of apple is.
So you have to use device only.
Happy Coding
According to the documentation, when using the simulator:
"The relocation reported by the
CoreLocation framework in the
simulator is fixed at the following
coordinates (accuracy 100 meters),
which correspond to 1 Infinite Loop,
Cupertino, CA 95014.
Latitude: 37.3317 North Longitude:
122.0307 West"
So, in practical terms, you should be able to build the app but you'll be unlikely to do anything useful with it.
You might wanna check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator
It reads a KML file generated by Google Earth to provide faked location updates. It also updates the blue userLocation dot in a MKMapView with the simulated location updates.
In Xcode 4.2 we can simulate . There is a location symbol on the debug area (while you run the app). There are some predefined locations . Also we can add new GPX files
The solution was to subclass CLLocationManager and define a new delegate #protocol, called DLocationManagerDelegate.
It is designed to be a simple drop-in replacement for CLLocationManagerDelegate that compiles down to a very thin layer when deployed on an actual device.
When running on the device it will return data as normal using CoreLocation, but in the simulator it will read latitude and longitude from a text file (defined in the DLocationManager.h file).
I hope this helps, the implementation is on the simple side and you have to startUpdatingLocation and stopUpdatingLocation to update the display.
http://code.google.com/p/dlocation/
I want to allow users to set the GPS information on the iPhone Simulator via GUI.
But I'm not sure how to archieve this - it seems that this tool called iSimulate does this somehow by installing an own SDK. But I can't figure out how they "override" / "hack" the simulator by that.
Thanks!
Added a second answer since there are now integrated features in Xcode (≥4.2). There are two ways to simulate location updates:
In the iOS Simulator, under "Debug/Location" you're able to specify a constant latitude/longitude or select several predefined profiles like "City Run" or "Freeway Drive".
In Xcode there's a new location icon in the debugger, right next to the Step Out button. It lets you select several hardcoded cities worldwide and add a custom GPX file to your project. The nice thing about location simulation in Xcode is that it also works on the device (just don't forget to turn it off again otherwise your auto timezone will be wrong!). The custom GPX file is nice, too, although it sometimes crashes Xcode if the GPX file is not recognized. Make sure you use <wpt> tags only:
<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
<wpt lat="47.52789018096815" lon="7.385249894876031"></wpt>
<wpt lat="47.52720984945248" lon="7.382647784661411"></wpt>
...
</gpx>
As far as I know, iSimulate is not employing any hacks. It is code that runs within your app on the Simulator which communicates with a device over the network. When it receives messages from the device (touches, GPS, acceleration) it simulates those events by calling your app's code as though the system had triggered them.
For example, to receive GPS location updates you must create an instance of CLLocationManager and then configure one of your classes to be its delegate. Well, on the iPhone Simulator you can instead start code that sends fake messages to your delegate instead. If you just call a delegate's method like this:
[delegate locationManager:nil didUpdateToLocation:newLocation fromLocation:oldLocation];
Your code won't have to know that the location update is fake. If you want to get fancy, you could create a new class that implements all the public methods of CLLocationManager but which sends fake messages instead. (Since Objective-C is dynamically typed, it won't need to be a subclass, as long as it responds to all the messages you send.)
As a side note, you can use these compiler macros to keep code simulator-only:
#if TARGET_IPHONE_SIMULATOR
locationManager = (id)[[MyFakeLocationManager alloc] init];
#else
locationManager = [[CLLocationManager alloc] init];
#endif
The iOS Simulator has full location simulation built in. From the "Debug" menu, you can explore your various location options.
Original answer posted while under NDA.
Check out the bottom right entry on this page. I'm under the NDA so I can't say anything except that it has saved me significant gas money. :)
1: http://developer.apple.com/technologies/ios5/
You might wanna check out my FTLocationSimulator at http://github.com/futuretap/FTLocationSimulator
It reads a KML file generated by Google Earth to provide continuous location updates. It also updates the blue userLocation dot in a MKMapView with the simulated location updates.
In Xcode 4.2 we can simulate . There is a location symbol on the debug area (while you run the app). There are some predefined locations . Also we can add new GPX files
Hy stephanos,
The information of the GPS cannot be changed. It is protected and I don't believe that iSimulate can change it.
As far as I know, iSimulate is a tool to send commands from a device to the iPhone simulator, like accelerometer, touches, orientation, etc, including the current GPS location.
The SDK of iSimulate works with the app. You have to install the app in the device and add the sdk to your project, so you don't need to buld and run your app to the device all the time that you would be doing normally.
Cheers,
VFN
Check out https://github.com/100grams/CoreLocationUtils
Just to extend #Ortwin Gentz answer:
If you need further config of every gps point in your gpx file. Take a look at this page:
http://www.topografix.com/gpx_manual.asp
It tells you exactly how you can provide further details like speed and height of a specific point.