I've implemented a macOS app + extension.
The extension might send notifications to the app via DistributedNotificationCenter.default() and postNotificationName(_ name: ...).
The questions is regarding to the app life cycle on macOS - what happens if the user minimized the app, and the extension (which is running) sends a notification with the 'deliverImmediately' flag.
Will the app be able to handle it, even while minimized? If no, any other way to achieve this behavior?
P.S - I didn't find anything at the documentation, and when trying to check what happens, sometimes the app got the notification, and sometime it didn't..so asking to check what is the expected behavior.
The app isn't paused while minimized. Being minimized is a state of NSWindow not NSApplication. The app's run loop still executes, perhaps less frequently, and of course, the window won't be receiving any keyboard or mouse events while minimized, but the app will still be able to process notifications, AppleEvents, network or file I/O, etc... You may need to "un"minimize if the notification involves user interaction in the minimized window with NSWindow.deminiaturize(_ sender: Any?).
If the app is hidden it also still runs, and you'll want to activate it with NSApplication.activate(_ sender: Any?) to do any UI.
Related
Initially the person before me set up a screen observer so that whenever the page changes, setCurrentScreen is triggered to send a event and log the screen. Because we use a bunch of open containers to animate page opening, the screen observer doesnt get triggered. So I went through the app and added some setCurrentScreen for those that the screenObserver missed, and while there I also added some logEvents to see if people are using specific parts of the app.
The way I set enabled debug view was in xcode, going to Product -> Scheme -> Edit Scheme and adding -FIRAnalyticsDebugEnabled and -FIRDebugEnabled Edit scheme
After ticking both of the above (or just one or the other), only these events are being triggered then the app stops sending events. Completely. What am I missing? output
I cannot find another issue about this. I am using the same package name in the app and firebase, otherwise I would have no output. All other issues are talking about no output at all. I have tried to do this on simulator and on actual iPhone and they both yield the same result. I have also set up a android emulator and have an actual phone. Tried it on both and same result. The above screenshot is from iPhone as I am on Mac and more comfortable working on a iPhone.
i have set IS_ANALYTICS_ENABLED to true in the .plist file and this did not work
Many people appear to have a problem where their AppDelegate's applicationShouldTerminate is never called. I have the opposite problem!
Often (at a guess 20% of the time) when I come back to my Mac in the morning, I discover that something caused my app's applicationShouldTerminate to fire. My app then ran its cleanup code, after which applicationWillTerminate fired. However the app never shut down — it's still marked as running in my dock, and when I click on it there, applicationDidFinishLaunching fires and it starts up. Because it was already running, the dock icon does not bounce.
The logs indicate this seems to only happen when I wrap up for the day and my Mac goes to sleep, possibly only after having been plugged back in after running off its battery.
At first I thought it might be because my Mac was trying to shutdown apps to install a system update but this happens even when there are no updates available. And no other apps on my system have the issue.
The same happens with my app on a friend's Mac.
I do have a "tricky" applicationShouldTerminate to get around run loop issues (nb. I'm using Promises):
var shuttingDown: Bool = false
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
log.debug("applicationShouldTerminate")
if shuttingDown { return .terminateNow }
shuttingDown = true
StuffController.shared.terminateRunningStuff()
.timeout(20) // If it hasn't shutdown within 20 seconds, force it.
.always {
// Tell the app it should now actually terminate.
NSApplication.shared.terminate(self)
}
return .terminateCancel
}
Can anyone suggest a reason my applicationShouldTerminate is firing without the user asking it to quit?
Turns out this is a feature not a bug (lol). In Mac OS X Lion (10.7) Apple introduced a feature called "Automatic Termination" where apps would automatically quit after a while of inactivity.
Note that this is intended to be invisible to the end-user; the app appears to be running in the dock, and should restore itself when needed, as if nothing ever happened.
It can be enabled or disabled via the "Application can be killed to reclaim memory or other extraordinary circumstances" configuration in Xcode (the NSSupportsAutomaticTermination key in an app's Info.plist).
I'm trying to programmatically return to the home screen in an iOS8 App using Swift. I want to continue the application running in the background though. Any ideas on how to do this?
Thanks in advance for the help.
When an app is launched, the system calls the UIApplicationMain function; among its other tasks, this function creates a singleton UIApplication object. Thereafter you access the object by calling the sharedApplication class method.
To exit gracefully (the iOS developer library explicitly warns you not to use exit(0) because this is logged as a crash ) you can use:
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
For example, my app exits when the user shakes the device. So, in ViewController.swift:
override func motionEnded(motion: UIEventSubtype,
withEvent event: UIEvent?) {
if motion == .MotionShake{
//Comment: to terminate app, do not use exit(0) bc that is logged as a crash.
UIControl().sendAction(Selector("suspend"), to: UIApplication.sharedApplication(), forEvent: nil)
}}
Swift 4:
UIControl().sendAction(#selector(NSXPCConnection.suspend),
to: UIApplication.shared, for: nil)
Edit: It's worth mentioning that in iOS 12 there's a bug that will prevent network connectivity if the app is brought back from background after sending the suspend action.
For that you should use following code
import Darwin
exit(0)
To force your app into the background, you can legally launch another app, such as Safari, via a URL, into the foreground.
See: how to open an URL in Swift3
UIApplication.shared.open() (and the older openURL) are a documented public APIs.
If you set the exits-on-suspend plist key, opening another app via URL will also kill your app. The use of this key is a documented legal use of app plist keys, available for any app to "legally" use.
Also, if your app, for some impolite reason, continues to allocate and dirty large amounts of memory in the background, without responding to memory warnings, the OS will very likely kill it.
How about setting of info.plist?
You can set "Application does not run in background" true in info.plist with editor.
Or Add this lines with code editor.
<key>UIApplicationExitsOnSuspend</key>
<true/>
There is no way to "programmatically return to the home screen" except for crashing, exiting your program or calling unofficial API. Neither is welcome by Apple. Plus the Human Interface Guidelines are also covering this.
In my appname-Info.plist
I have 'Application does not run in background' box checked.(it is ticked)
But when i press the button under the screen to close the app, and then double press the button it shows the list of apps and my app is there among the list of currently running apps. Does this mean that my app is running in the background?
If so is there a fix for this? I'd like to make sure my app is completely dead when user quits it.
Thanks
-Code
Your app is not running in the background after you close it.
Even if you see it in the switcher app list.
Application has different states
Active
InActive
Running in Background
Your application become in-active, not running in background.
Aplications are allaowd to run in the background only for:
Playing music.
Navigation needs.
VOIP (as Skype).
And you should explicitly ask the permission and set the appropriate code for doing that and not only check the 'Application does run in background' in the info.plist
The list you get when you double tap the home button is not a running applications list. That's a common misconception. It's actually a list of recently launched applications. Therefore it makes sense for your app to be in it even if it doesn't multitask.
Today i updated my 3GS i-phone to install my application to see it's functioning well in OS4,when i'm running the application and tap the home button it's goes to multitasking bar,then again i get the application from there it's goes to previous state where i was.i think the behavior is OK. but problem comes when i kill the application in multitasking bar and run it it's come to same state,simply it's ignore the login screen.
My question is when i kill the application i want to get my login screen, not the previous state, this application is working fine in 3GS,can some one please help me to fix this issue?
Thanks
Sam.
Sam,
If you don't want the OS to save state for you, you should place the key UIApplicationExitsOnSuspend in your info.plist file.
More information here: http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
This will kill the app when the home button is pressed, instead of suspending it into the background (which is what iOS4 does for multi-tasking).