how to make a view appear only if is the first time? [duplicate] - ios

This question already has answers here:
Show screen on first launch only in iOS
(8 answers)
Closed 9 years ago.
Thanks in advance .
I wanna make a view appear only if the application is launch for the first time, I have work with a similar code to display Alerts, but I can find a way to make it with a Storyboard view ? For example my idea is : in the image below I have 7 buttons so I want the user to select which Country/Button they wanna use after this first time launch (it will be a button where they can change it back ) and how can I save the value of the button (the one that the user choose) so that every time the app launches again it goes straight to the one they selected when the app was installed ?
Thank you .

There are two pretty easy solutions I can think of.
First, in both instances, you'll be duplicating much of the same logic you say you've used previously in displaying a UIAlertView.
Option 1: Have the view with buttons that should only be displayed once as the first view. In the viewDidLoad method, check whether the app has been launched before and a button has been selected. If a button has been selected before, just go ahead and perform the segue straight from the viewDidLoad into the rest of the app.
Option 2: This time, instead of starting with the 1-time view, start with the standard first view. Check if the app has been launched before or not, and if it has, perform a modal segue into the view where they select a button (otherwise just don't perform the segue).
I'm certain there's a more elegant solution to get this work in a better way, but this is a pretty simple implementation that should be quite easy to get working.

I would us an NSUserDefault here. First check for the presence of a preference for the key you specify. If it doesn't exist you'll want to show the region selection view. If it does exist just use the region stored in the preference.
This way, if the preference every gets deleted or lost, the logic will be small enough that the user can recover fairly quickly.

Related

ScrollView and viewcontrollers

Here is context for my question, this is an optional read:
I have to develop an app for a
school project. At the end of the year some people I don't know will
listen to me presenting my app, and review my presentation and my app
(note that they will probably not be app developers, they are usually
IT professors) (note also that I'm allowed to ask for help to anybody,
and I can use internet since I do this mostly on my "free time")
So since October I'm developing my app, that takes a lot of time
because this is my first app. And here comes the issue:
My app is a giant Scroll view with 5 NavigationsControllers, each containing a ViewController. These ViewControllers sometimes have buttons that leads to an other ViewController. The problem is when I use these buttons, and another view controller is displayed, when I swipe right or left the ScrollView scrolls and another ViewController from the scrollView is displayed. I don't want this to happen because most of the time the ViewController displayed after the tap on a button is not meant to stay, it's generally a form to send data to the server.
As I think this is difficult to understand, you can download the project on Github
Is there a way for me to disable scroll on chosen ViewControllers? or should I change everything to avoid using a ScrollView?
Bonus question:
Is it a really really bad idea to make an app this way, or did I just miss something?
Thanks for your help!

How to make my LaunchImage load at the same time as the application?

As the application loads, I want to make an image load at the same time, for example, a line would elongate form either side as the application loads, and when it has finished, the line would have reached its maximum length. I have seen this in a few websites, like rime arodaky for example, but I want to this for an iOS application. I have searched on Google but couldn't find anything!
Does anyone know how to do this?
The launch process if we REALY simplify it to accommodate your question, can be split into two parts.
The first part you do not have any control over, and during which a launch image is shown.and it ends with a delegate call-back on the application delegate called
applicationDidFinishLaunchingWithOptions
The second part is you might have some application specific behaviour which requires no activity from the user but you app still isn't interactive.
You need to implement such a progress bar yourself. There is no built in support for this in any of the app templates in Xcode.
You can only do what you want during this second phase. But you have absolutely no control over the first phase, except for that static non-animated launch image.
I think you can just add a photo as a launch image, launch image is just an image.Then you can add the animation when your first view controller appears.You can fake it this way.

TodayViewController recreated every time Notification Center is shown

When trying to develop a Today Extension for iOS 8 I found a weird issue. It would seem that the View Controller I'm using is being recreated every time the user opens Notification Center. This means that there is no data retention and hence no way for me to know if the extension needs to update or not.
The main reason for wanting to do this is that I want to preserve the height of the widget (Using preferredContentSize). The problem is that when the view loads this value always gets reset which leads to the widget jumping around in size. The Stocks widget is an example of how it's supposed to work and they've obviously solved it so there has to be some way of retaining the data between different "sessions". I can also tell from the debugger that the process continues to run, so it's just down to something in Apple's code forcing the View Controller to be recreated.
My question is, is this a bug? Or is it based on some setting or some property that I'm missing? Or is it maybe just the way it's supposed to work? If so, what is the workaround?
That's the way they work. Save your information to the device so you can reload it the next time you launch, along with the update time so you know if it's out of date. For small amounts of data, just use NSUserDefaults. For larger amounts save to a file, CoreData, sqlite, etc.

Screenshot that taken by iOS when (before) application go into background?

I hope that you all know about it, iOS takes screenshot before your application goes to background.
I got it from official document.
Remove sensitive information from views before moving to the background: When an app transitions to the background, the system takes a snapshot of the app’s main window, which it then presents briefly when transitioning your app back to the foreground. Before returning from your applicationDidEnterBackground: method, you should hide or obscure passwords and other sensitive personal information that might be captured as part of the snapshot.
So, Here We can hide our "sensitive personal information" and the system takes a snapshot of the app’s main window, so we can not change its feature.
But I want to know..
1) If in my application I'm at 4th View, and my app goes to background then system takes screen shot of which view/page? first one (start up view of apps?) or 4th view/page of the app ?? (here is little confusion for me).
2) Can we fire any action when system is taking screenshot or any notification is available that will inform us of system taking screenshot ??
3) I just want to know, is it possible to take screen shot (programmatically) before my application launch ?? If YES then give me suggestion for how to do it. And if NO then where/when I'm able to take screenshot (I mean at which minimum stage of application we'll be able to take screenshot ?) ?
It will take a screen short of the top most view, actually it is taking a screen shot of the window which is displaying your app.
No there is no notification that the screen shot is going to or being taken. You should just handle the handle it in the applicationDidEnterBackground; method. Just a stated in the documentation
No this is not possible, how do you want to execute any code before you app is running? The OS will make the screen shot, just be sure to have everything hidden in the applicationDidEnterBackground;. The minimum state is that your app is up and running.
What I've done is on of my apps is as soon as my app gets pushed to the background place an extra view on my UIWindow. Thus when the screen shot is made this view is captured.
1) There is just one screen. The screenshot is taken of that screen. In your model case that should be the 4th view controller's view. However, it is quite possible that your 4th controller's view does not cover all of the screen or has transparent elements. In that case parts of the 3rd or even 2nd and 1st view controller's view are part of the screen.
It is a screenshot not a view controller shot or anything.
2) You understood the documentation all right. The screenshot is taken after you returned from applicationDidEnterBackground. There will be no further dokumentation.
3) No, you cannot execute any code before your app is invoked. However, I have the feeling that you are looking for something different than you asked literally.
For some other reason I have executed a small program in the simulator by implementing the main function only even without calling UIApplicatoinMain. This is the first point in time where code from your app may be executed, although that would not be exactly "out of the book". If I remember right, the screen was blank/black at that point in time. So if you are asking for a way of creating screenshots of other apps, this is not the way to go forward.
It is not taking a screenshot quite like a user pressing buttons.
This functionality is related to state restoration. When the application goes to the background it flattens the view hierarchy for each screen into a screenshot used for the task manager. If you are opted into state restoration it will also persist the state of the user interface. This means that a person can bring the application back from the background state and potentially see sensitive information that way as well, which may be something you need to handle.
Preventing information from being included in the state screenshot is covered in Tech QA 1838.
1) I'm pretty sure the system will take the snapshot of the current visible view, so the last one on the stack, not the first one
2) Also, there will probably be a Notification to let us know that the system is going to take a screenshot (otherwise how can we hide sensible information? :) ), but I'm afraid we're currently under NDA I guess?
3) What do you mean "take screenshot before my application launch"? Your code starts executing when your application launches, so this question almost makes no sense :-/
You can anywhere in your application take a snapshot of the screen, however, and there are many stackoverflow posts for that

Transparent splash screen on the first (and only first) startup of an app for instructions (iOS) [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 9 years ago.
I have a simple app where the buttons are in the form of logos rather than text. Things like undo, reset, settings, etc... I'm trying to keep the interface simple, so I just want to have instructions shown on the first ever startup of the app. I've seen this done in other apps, where a transparent subview with labels is loaded, then touching the window dismisses the subview.
I currently have the launch count stored in NSUserDefaults, so I just need to figure out how to add the subview on top of the main view, which then gets dismissed on a touch. I would like to just load a png that fits the screen size in the subview.
This seems simple, but I am having trouble not overcomplicating this process.
Thanks!
check for your NSUserDefaults for the first launc and if it is then you could display your image as a modalViewController and to dismiss it on touch use touchesBegan metod to dismiss this controller.
This seems simple, but I am having trouble not overcomplicating this process.
What have you tried?
There's not much required to add a view to another view, but you don't even have to go that far. You could add your instructions view in your .xib/storyboard file and set it's hidden property to YES. Then all you need to do if the user is launching for the first time (or if they ask to see the instructions again) is flip the hidden property to NO, and then back to YES when they touch it.

Resources