last day (15 days later) » 

8:33 PM
0
Q: Why does Xcode simulator launch app with didEnterRegion call, while iPhone does not?

elightI'm troubleshooting a location-based app launch cycle that works fine on iOS simulator, but apparently does not launch the app on an actual device. I've set up UNNotifications for both enter and exit events. Both the simulator and the device(s) register and display these notifications. The next...

 
If you are getting notifications then your app is running. You won't get a call to didFinishLaunching if your app is already running
 
@Paulw11 But isn't it true that "User-facing notifications communicate important information to users of your app, regardless of whether your app is running on the user's device" - Apple
Also, the app is definitely not running on simulator because the debug process has not yet attached (Launch manually option selected in "Edit Sheme..."
 
Do you post the notification by executing code in your didEnterRegion/didExitRegion functions? How would these notifications be posted if your code wasn't running? Or have you created the notifications with a region trigger? It is always better to show your code in the question than describe what you have done to remove ambiguity. Have you requested and received "always" location permission?
 
Edited question and included code. "Always" authorization...
Is it possible, that in ApplicationController.swift, delegate?.handleUNEvent(note: "ENTER: \(region.identifier)") gets called, but not the code after it?
 
You haven't shown any code after it. Is there code after "start the launch cycle"?
 
8:33 PM
Sorry, removed for brevity. There is code and it works just fine.
Oh neat-o.
 
I am a little confused. Your application is running because the notifications are running. You say some code isnt running, but then you say that code works fine.
 
Yes, the app posts the notification because it is running. And according to the AppDelegate method handleUNEvent(note:), the app presents an Alert box if the app is active, or sends a local notification if it is in the background.
When the app launches, it does this - the code after delegate?.handleUNEvent(jnote:) does not get called.
I'm confused too.
 
But you haven't shown that code. What does it do?
 
The didEnterRegion method is only called after appDelegate.didFinishLaunching (where CLLocationManager boots up). My ApplicationController singleton is, however, initialized OUTSIDE of any appDelegate method as a class property.....could that be it?
import UIKit
import CoreData
import UserNotifications

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var appController = ApplicationController.sharedInstance

func application (_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
appController.delegate = self

// Set up Location services in case of location notification (or just do it anyway for now)
 
I am trying to understand what you expect/want to happen when your app launches in the background vs what is happening
 
8:45 PM
The launch cycle involves just iterating through CL's monitoredRegions and match the entered region ID with a list of known regions in the app.
What could be happening is the app survives in simulator but for some reason crashes on the device and I have no way of knowing because I'm not debugging it. I'll try and hook up wireless debugging next I think.
 
Ok. But you won't see any console output while you are walking around with the phone
If it crashes you should have a crash log in the devices window when you reconnect the phone
 
No. And I'm on a mac mini. I'd have to put the whole project on my macbook. And drive around with it.
Hmm. Right!
 
So I still don't understand what you expect to see on the phone when you are walking around apart from the notifications, which you said are being shown
 
Dang it. I have a crash log. It is from my test outing. Goddam AudioKit is at it again!
Thank you Paul! I have to go. I'll update the post when I bring this to a conclusion.
 
Ok. If you solve it you can add an answer to your own question
 
8:52 PM
Have a great day
 

last day (15 days later) »