How to get geofencing didEnterRegion delegate method call when app is closed - ios

So when the app is closed (not in background, but totally closed), how app can get didEnterRegion delegate method call when user enter a region? And how I can simulate that in simulator.
Thanks.

Your app will be reopened (into the background) to handle the update. You can not test this in the simulator.

In the simulator go to the 'Debug :: Location' submenu and either select a test location or enter lat+long data under 'Custom Location...'
If your application is not running, then it can't get location services. However, if you can add a 'Passbook' aspect to your Application then you can get Passbook to monitor a location for you. See https://stackoverflow.com/a/14040276/1286639

If you use region monitoring, your app will be restarted by the system.
It's hard to debug because when you close the app, the debugger will detach.
Try this:
Start the app on a connected phone and simulate new locations using Xcode. To do this, create a GPX file with multiple locations. When the debugger is running, there is a little location arrow next to the start/stop/pause buttons that allows you to select the GPX file with your track. Xcode will then simulate moving from point to point in the GPX. You can verify this by opening the Maps app and watching the location move around.
When you kill your app, the debugger will detach, but you can reattach with Debug->Attach to process->Your App Name. That will get you the console back, but you won't be able to continue simulating the location in the running app. Also it's not clear if the simulated location resets back to normal mode when you do this. I get different results all the time.
Region monitoring is flaky at best. I have been trying to get reliable results since iOS 5 and it's a real mess with unpredictable results...

Related

How to debug a crash which happened when come back from background

There is a crash happen when coming back from background through app icon.
However I cannot see any detail info in console log. There is a signal to terminate, but we cannot find signal number.
<FBApplicationProcess: 0x117bcb930; Maixxxx; pid: 1762> exited abnormally via signal.
Process exited: <FBApplicationProcess: 0x117bcb930; Maixxx; pid: -1> -> <FBApplicationProcessExitContext: 0x17103f820; exitReason: signal; terminationReason: (none)>
The procedures to reproduce my crash is as follow:
Start app through click on app icon.
Use the app as normal user.
Press home to put it in background.
Wait for some minutes.
Click the app icon on springboard screen in order to use it again.
The app crash&exit.
Since the crash only happen when coming back from background, and required to enter background for some minutes, I cannot run in debug mode with lldb attached.
I didn't use any of background features.
Also, I didn't see any crash report in Fabric's Crashlytics. So I think signal handler could not be called neither?
How to investigate this kind of problem?
These things can be tough, I know that from similar experiences. Without knowing more about your app I can only offer hints and no definitive answer, but perhaps this helps you.
The fallback and tedious approach to use direct logging with print and so on notwithstanding there are a two ways to try to "catch" a process.
However, first let me stress that "background" is not always the same and people unfortunately use the term often loosely. Depending on what state transition causes your crash you might run out of luck and have to simply experiment using manual logging. Apps can be in background, i.e. not in the foreground, but still running. This is usually the case when the debugger is attached, otherwise it couldn't do its job. Alternatively they can be suspended (or even terminated) by the OS. The debugger prevents this, which you probably already figured out.
The two things that might help you are:
If you're using background fetch, i.e. "coming back from background mode" as you describe it happens automatically you can activate the "Launch due to a background fetch event" option in your build scheme's "Run" configuration section.
Run your app from the Home screen, put it into background with the Home button and wait a bit (you've probably done so in the past already to get a feeling for when the crash would happen). Your app should eventually go into the suspended state (but you have no way to actually see that anywhere AFAIK). Instead of getting it to the foreground again via the multitasking UI, simply attach the debugger again via the "Debug - Attach to process" menu. This should get your app from the suspended state back into the background state, where the crash probably really happens (if it were to happen when coming from background to foreground you probably would have been able to debug it as usual). Hopefully the debugger has finished attaching to it in time, otherwise I'm out of ideas. :(
I haven't run into this specific problem myself personally, but I know background stuff can be tricky. Maybe this discussion also helps you (I took part of my info from there as well).
Run the app in debug mode on a real device. Press the Home button to send the app to background and continue the debugging. Then you can bring the app to foreground and keep debugging, or put a breakpoint at applicationWillEnterForeground.
You can't debug this on the real device. When the debugger is attached, your apps will never go to background mode in the real device.
You can try to debug this on a simulator.
Anyway please check your class attributes and set attributes to strong to make sure this is not happened by missing attributes.
I have read several StackOverflow questions that have FBApplicationProcess. Usually, this one happened by missing array or something when the app started.
Best regards.
I have gone through all the above answers and all have given proper answers. Though, I would like to share my point of view.
If the app is running on any iOS real device with debug mode and wire plug-in or even on Simulator, App will never go in the background.
If the app is running without wire plug-in or run without Xcode(directly launch the app in iPhone) and then put the app in the background, the app will be running in the background of next 3 mins. After 3 mins, the App will automatically be suspended and removed from the main thread. Now, when we open the app again, It will be considered a fresh launch.
If your app having any Background Capabilities ON, then your app will be alive even in the background, but you can't do any UI changes during that time.
To keep app alive in the background, Background Capabilities must be handled properly. ie. If Location is used in your app with 'While-App is in Foreground' condition, app will not run more than 3 mins in background. So, If you want to run your app continuously in background, you must have to represent proper reason in Info.plist file with Battery drain word, or else, Apple will reject it.
Ping me for more detail on your question.
Thanks.
Crash logs still available on your test device.
To get the crash log try the following steps:
Connect your test device to the Mac through USB.
Launch Xcode. Go to Windows > Devices and Simulators.
Choose your device from the devices section on the left side of the screen.
Select View Device Logs button.
Identify and select the Crash Log to see the contents.

My application is not showing under location services (Settings->Privacy)

I have developed location based application and it is able to get user's location but there is strange thing in it. Under setting->Privacy->Location Services, it is not showing my application. It is only happening with iPhone 6 Plus for other devices it is showing.
I'm pretty late to the game, but I had the same problem on an iPhone 8. The app would just not show up under location services. On other devices it was showing up fine.
The only solution that worked, after spending hours on finding a non-existent bug in my code, was to Reset Location & Privacy in Settings -> General -> Reset.
I had the same problem. Turns out I simply didn't open the app and get to the prompt to allow the location services.
As long as you don't get the prompt and confirm in the app, it will not show in the Privacy->Location list.

Do location services not update on someone elses test iPhone?

I am not getting background updates on another test iPhone. I have an application built and running fine on my own test iPhone. The simulator works fine as well with testing. Both can keep pulling the location services while in the background. I test this by spitting the lat and long into the debug area. Even when in the background, both spit the lat and long and keep chugging through.
When I put it on my roommates iPhone to test it, it does not keep updating in the background. Other than that, it works fine. I went into the development part in his settings and could not find anything there either. Is there something I am missing with allowing an the app to run in the background?
Go to Settings -> Privacy -> Location Services (should be ON) -> Name of your app (check if you allow using location)
Check Background App Refresh setting in Settings/General
Apple - getting the user's location
When a user disables the Background App Refresh setting either
globally or for your app, the significant-change location service
doesn’t relaunch your app. Further, while Background App Refresh is
off an app doesn’t receive significant-change or region monitoring
events even when it's in the foreground.

UIAutomation : Change location when the app is in background

I am working on UIAutomation. I need to change the location when the app is in background. I have tried following line of code:
var target = UIATarget.localTarget();
UIATarget.localTarget().deactivateAppForDuration(30);
target.setLocation({longitude:77.50, latitude:12.50});
but target.setLocation is not getting called until the app comes to foreground.
Could any one please tell me how I can change the location when the app is in background.
Unfortunately UIAutomation can only automate the application it's attached to. When the application is not "active", it has nothing to talk to. Using lockForDuration, deactivateAppForDuration , etc blocks while it relinquishes control to the system, making your app inactive. While the application is in that state UIAutomation can't send it any more messages.
I would recommend filing a radar asking for the ability to set the location while the application is inactive.
When I ran into a similar problem in the past I had to use AppleScript to change the location of the simulator to get the effect I needed.
You have since updated your comments indicating you are testing a navigation application. Well! That's a little different. If you do not ACTUALLY require UIAutomation and were only trying to use it as a way to set the location:
Xcode does allow you to simulate a route using GPX files, and this CAN be used with Instruments.
Find an appropriate GPX file, preferably one that is a track.
Go to the scheme for your project. In the Run action, go to the "Options" tab. Check "Allow Location Simulation" and use the drop down list to add your GPX.
Run your application from Xcode.
...
Profit!
I think you can use update part in background as service. Though i am newcomer in this world. You can try this. Thanks
if you want your app to execute methods in background, you have to enable "background mode" in your capabilities tab of your app. you have to choose a mode, for example "location updates". but be careful: apple has restrictions of what kind of apps are allowed to run in background. the "location updates" mode are only allowed for apps like navigation apps. see the app store guidelines for details.
if you dont set the "background mode" to yes, your app has 5 seconds to finish executing tasks after turning to background and then all tasks will be stopped and never called until your comes to foreground again.
Refer the http://code.tutsplus.com/tutorials/ios-7-sdk-working-with-background-fetch--mobile-20520 for the Background fetch. I hope this helps you.

How can I avoid XCode resetting the location on my iPhone every time it runs

Every time I run XCode, my location is being reset to a location in London. It doesn't recover until I reset my device.
How do I avoid this?
This took me a month or two to spot and track down, so I am posting for the benefit of others.
as Apple Customer Support were unable to diagnose it, and even went so far as to swap my device for a new one- which of course didn't help. There was nothing about this on Google.
I eventually diagnosed it by setting "Find My Friends" to geofence my real location and send a message when it spotted me leave. The second I started running my app on Xcode it pinged instantly.
There is a setting in XCode that sets the GPS to a chosen dummy location whenever you run your app. It can be found by selecting Product>Scheme>Edit Scheme from the top menu, then select "Run appname" on the left and "Options" at the top. The one you want is "Core Location: Allow Location Simulation."
Just uncheck that box. Problem solved.

Resources