SwiftUI - How to know if a new app window has been opened after clicking the X button (Mac)? - swift

I know there are functions in the AppDelegate like applicationDidFinishLaunching, but I haven't found a way to know when the app has been reopened after closing it (without quitting it) using the X button.
I'm trying to know which function (if any) is going to help me with that.
I'm trying to corroborate which one works by printing something, for example:
In applicationDidFinishLaunching I use print("App Launched").
In applicationShouldTerminateAfterLastWindowClosed I use print("Last Window Closed")
So I need one that theoretically prints App Reopened.
I've tried so many, including:
awakeFromNib
applicationDidBecomeActive
applicationDidUnhide
But none of them have work for me.
Thanks in advance.

I think the callback you're looking for is NSApplicaitonDelegate.applicationShouldHandleReopen(_:hasVisibleWindows:)
These events are sent whenever the Finder reactivates an already running application because someone double-clicked it again or used the dock to activate it.

Related

Xcode Swift 5 MacOs app empty window when archived but works when running it from Xcode

I am building an app for Mac which logs into a website based on login and password collected from textfield and secure text field, then app opens an url which is created in my app based on date range selection with use of two date picker cell calendars. Next app displays html data in webWiev (using WKWebView), converts html to string using extension NSAttributedString and then saves retrieved data as txt file. Everything works as expected as long as app is run from Xcode "play" button. Problem is if I archive this app and launch it, it will bring up an empty window without any button, calendar or textfield. There are no errors, no crash logs on organizer, nothing.
I decided to perform a little test. I build another view controller with only one button which upon clicking will show my app main view controller. After archiving this modified app and running it outside of Xcode a window shows view controller with one button which is correct. But after clicking it nothing happens. App works great if running "inside" Xcode, a pushbutton shows main ViewController correctly. Do You have any clue what can be wrong? thank You!
Edit 1. So I found a discussion on apple which mention this problem. It is associated with IB WKWebView and problem is already known since some time. Now I have to get around the problem. Apple forum link: https://forums.developer.apple.com/thread/116047
Did you embed WebKit.framework to your app?
After comment that I wrote, I founded a solution and solved with this method.
Please check it out.

How to simulate the very first start of an app in Xcode 6

I need to test some behaviors of the iOS 8 at the very first start of my app. Is it possible to simulate this in Xcode 6? If yes, then how?
Deleting the app will do it but note that certain pieces of information will be cached for a while like your permissions settings (notification, calendar, etc.). You can go to settings.app and reset settings to clear those out if that matters in your use case.
If you mean the FIRST start of the app, then what I did to achive this is, on start (viewDidLoad) check in the NSUserDefaults for example ,if the value "hasAlreadyStarted" exists (NSUserDefaults.objectForKey(..) ), if not, then its the first start of the app, and then i would set the value to true, so when you close the app, and open again, the value will exist.
Dareon I'm not sure what exactly you want to achieve. In Xcode 6 yes you can simulate your app from start. If you want to test behaviours I think you are looking for instruments. Right Click on the Xcode icon in your dock select option and choose instruments. You can add several instruments your phone or emulator support like connectivity or gps or memory to see exactly the behaviour of your app. Hope that helps
Well if by very start of the app cycle you mean before the app loads, there is a way.
In your ViewController call the ViewWillLoad function:
class ViewController
{
override func viewWillAppear(animated: Bool)
{
// your code
}
}
This event will be called before the view loads or appears.
Hope it helps :)
As Shanti K said in the comment, if you delete your application from the simulator and then run it again, you will be simulating the first run. To delete the application from the simulator, you mimic the same behavior on a device.
Click and hold on the icon, until they start shaking. Click the close X next to your application, and verify that you want to delete it if it asks. Then Shift + Command + H to simulate hitting the home button.

SA_OAuthTwitterEngine login keyboard doesn't show after first launch

I'm using the SA_OAuthTwitterEngine to integrate Twitter into on of my iPhone apps. Loggin in and sending tweets are working fine. But, when I completely terminate my app so it will start up from the beginning, I can't login again using the SA_OAuthTwitterController because the keyboard will not show up. The input field also doesn't respond to the Mac keyboard when using the simulator.
I've searched for similar problems, but they don't help me out. I've found a lot of similar problems, where calling makeKeyAndVisible for the app delegate window solved it. This doesn't work for me. If I set the modalview's alpha to .2, I also don't see the keyboard behind the view controller.
Weirdest thing is that everything works after a fresh reinstall for as many times as I want, but after I've terminated the app, the keyboard doesn't show op anymore.
Can anyone point me in the right direction?
Thanks in advance!

Not able to enter a string in the TextField of UI-(iphone)

I brought a new MAC-MINI before this i was using MAC BOOk Pro..
i am facing some problem with xcode, the problem is when i run the Application where ever there is a TextField in the UI when i click to enter its not taking input,it takes hardly 1 or 2 strings and throws thread....
when i try to enter its throwing Thread in main() function telling EXC_BAD_ACCESS...
NOTE:The apps which were working before in Mac book Pro's xcode i mean apps which contains TEXTFIELD in the UI is also not taking input in the present xcode of MAC MINI.
if i tried without writing any code just placing a TextField in the UI and running it ,even then i am not able to enter anything in the UI its just throw Thread in main() function EXC_BAD_ACCESS..
I am not able to solve this issue may i know why its happening like this?
ITS NOT TAKING ANY INPUT IN TEXTFIELD OF PREVIOUS WORKING APPS AS WELL..
Is the problem with Xcode?
Plz Suggest me to solve this issue..
Thank u
Are you setting an object as the textField's delegate?
When you type in the text field, it tries to call its delegate (if it's not nil) to notify about a change in the text. If for whatever reason the delegate is dealloc'ed, you get this type of error, as the textField is trying to reference a deallocated object.

My app not geting terminated after pressing the home button

i am developing a ebook reader and i am facing the following issue. if i close the app and reopen , then it opens exactly in the same state as it used to be before closing. I suspect this may lead to a lot memory leaks. Is this the right way for the app to function? and will this behavior cause any memory leaks?? can anyone help me with this... I dint know what title to put on top.. Please apologize me if the title was misleading.. thank you.
This is the expected behavior. After the introduction of iOS4, applications will keep their state between launches. Applications get terminated when the system is running low on memory, as the system terminates applications not recently used to free memory. This will not lead to memory leaks. For users running iOS3 pressing Home will terminate the application.
See Understanding an Application’s States and Transitions and Multitasking for more information.
right appropriate code in delegate file
-(void)applicationDidEnterBackground:(UIApplication *)application
{//exit(0);
}
if nothing works write exit(0) in this method.
You can add the BOOL key: "Application does not run in background" to your info.plist and set it to YES. Then your app should be terminated when you press the home button.