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

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.

Related

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

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.

iPhone - Sending the app to the background

In my app, when it runs for the first time, it shows a UIViewAlert and offers you to see the preferences for the app - and the user has 2 choices - yes or no. If the user hits no the alert fades away and the application continues running. I want to set it in such a way, that if the user hits yes, my app will go to the background, the settings tab of the app will be opened (I added a settings bundle to the app). Is it possible to do such a thing? Thanks!
No, this is not possible. But you can create a settings view in you app and show it instead of trying to open the settings app.
Normally, you do want to encourage users to use your app as long as possible, and making them quit your app yourself is not the best way to achieve that.
No, this isn't possible.
But you could use InAppSettingsKit and modally show a view controller with the settings inside the app.
You can find out more here - http://www.inappsettingskit.com/

iPhone: What is the correct way to leave an Application?

Hallo Everyone,
with the iOS 4, the iPhone is supporting Multitasking, what is very nice, but something I do not wish to support in my Application. I mean, when the user press the Home-button, I want my application to finish and not to enter in Background. With the iOS 4, when the User press the Home-button, the App calls the applicationDidEnterBackground: delegate's method to enter in Background and in order to "force" the Application to finish when the user press the Home button, I've done following implementation:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//save everything...
exit(0);
}
PROBLEM: I've noticed, that exit(0) brings the Application immediately to finish, without calling deallocating methods like "dealloc", and I think that is not a good programming style. So I would like to ask you guys, how to bring the application to finish in a "nicer" way.
Thanks in advance.
What you actually want is not to exit the application (which is as mentioned not allowed), but tell the OS you would rather your application be killed rather than backgrounded.
There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated.
That's two questions:
How to programmatically exit an iPhone app - duplicate
Proper way to exit iPhone application?
How to cause an iPhone app to not go to background in iOS4:
Add the UIApplicationExitsOnSuspend key to your info.plist and set its value to YES
http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
One answer above says "There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated." with Xcode 4, the info.plist value is "Application does not run in background" of type Boolean, so setting this to YES will have the app exit when the user presses the "home" button.
You are not allowed to. I know from experience: got an app rejection from Apple because I've exited (that was two and a half years ago but I doubt they've changed their policy here). There's a "private" (i.e. not mentioned in header file) method "terminate" on UIApplication, IIRC. But Apple says you may not do that. Only thing you can do is to show a dialog, asking the user to press the home button. But in turn doesn't work if on a device with multitasking enabled... so I guess you really have to change your application in such a way that you can throw away your state on applicationDidEnterBackground and start afresh on application on applicationDidBecomeActive.

Reinitializing iPhone app when it relaunches

I am building an iPhone app. Currently when I close the app and relaunch it, it relaunches on the last viewed view. Instead I want to be able to reinitialize the app, and present the view that's most appropriate for the application's state (based on what's in the database).
How can I do that?
You have two options. You can follow Petesh's suggestion to make your app always terminate, or you can implement -applicationWillEnterForeground in your app delegate and reset things there.
I presume it's iOS4 - your app is not being terminated in this case, it is merely being suspended.
You need to follow the instructions here: http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-apps-exit-for-real/ which will terminate the app when the user presses the home button.
You need to add the appropriate 'correct view' logic to your application's start-up code once you've done this.
For the purposes of expediency, I'm adding the instructions here:
Open your info.plist file
Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
Set the new key to YES or Fill in the tick box

iPhone app remembers last state (multitasking?) unwanted behavior!

User launches the app, quits, relaunches and the app shows up in the exact previous state, as if the app didn't quit at all. I have no custom save state support, so this is really baffling. It happens on one of the user's 3GS, but not on my 3G. Which seems to indicate that this is OS4's multitasking at work, because 3G isn't supported. If this is true, is there a way to turn off this behavior?
So, if your app isn’t supposed to use multitasking at all or if you simply wish to disable it during development or debugging, all you’ve to do is to edit your project’s info.plist and depending on how you’re editing it:
* Raw text editor
Add a property named “UIApplicationExitsOnSuspend” and set it’s value to ‘Yes’
* The XCode GUI plist editor
Add a new row and select “Application does not run in background” (or type “UIApplicationExitsOnSuspend”) and then toggle the checkbox
http://www.alexandre-gomes.com/?p=545