This question already has answers here:
Force iphone app to restart programmatically?
(7 answers)
Closed 9 years ago.
I have an appdelegate that contains a lot of objects, which are initialized and
accessed from various places in the App.
I have a view controllers also in the appdelegate, and at some point in the Application, i need all of that to be reinitialized like the app is firstly run. and the appdelegate is firstly initialized.
How can i achieve that?
the [appDelegate finishLoadingWithOptions:nil] didn't work for me, because it doesn't
reinitialize the view controller which i connect using IBOutlet.
Please don't advise me to do it differently, because i am working on
project that is not of my work, and poorly documented.
Sounds like you basically want to totally restart your app. If that's the case, this previous question is going to be your best bet (I'm marking this as a duplicate as well for that reason).
That said, I think it would be well worth spending some time pulling out the data from your app delegate into something more appropriate. The application delegate is certainly convenient for storing data used throughout your app, but it's not really appropriate.
I know you say "please don't advise me to do it differently", but even though it's not your own code you could still re-factor it and make it better. Hopefully you'll be able to!
Related
I'm programming in iOS not so long. I was mainly programming UI related stuff like animations, custom UIControls etc.
I need in my new app to:
Display loading activity indicator and in the same time:
load some remote data from server parse them and store in local core data
load some data from local core data
get user position from location service
After this I have all data needed to display next view controller and dismiss loading indicator.
Question is how can I do this all? I need to support iOS9, iOS10, 11, 12. I understand that this needs to be done in background threads and then I need to merge all data from each task and switch to next view controller. I can't use any external libraries like rx-swift or promise-kit. Maybe there is any experienced iOS developer who can give me some main guidelines how to approach to this kind of application flows? I can imagine there is a lot of ways I can do it some of them are better and some of them are worse. Any guidelines would be very helpful for me. Thanks.
It's a very complex question and as you said it's possible to solve all this problems in several ways. But for sure i can give you some core-hints about which steps is better to follow:
Run in a separate thread the management of all stuff regarding to the Network communication. Maybe you can run it on a separate queue using the class DispatchQueue(). Once you received the data, in the same thread, maybe you can directly convert these information and store them inside a CoreData database.
To store into CoreData you need at first to know how it works, so basically search for some really easy tutorial about how to create from zero your first database inside XCode. After you have been able to run and execute a very simple one you will be able to pass to the second step and so try to integrate it with the data you have previously downloaded from the network. Here a good article for you: https://www.raywenderlich.com/7569-getting-started-with-core-data-tutorial .
To get the location is a separate field of study, because you have to study which background modes are allowed in iOS (And actually are allowed just a few). After that you will need to figure out in which category of background-location application your software belongs. After that you have to dig deep and discover how protocol and delegates works inside Swift/Objective-C in order to properly manage the last location value retrieved by the sensors. Here is a good article for you: https://www.raywenderlich.com/5247-core-location-tutorial-for-ios-tracking-visited-locations.
At the end when you interconnected all this flows you can think about how to display the loading indicator. Basically you need to drag and drop it from the tools into the storyboard, interconnect it by using the IBAction or IBOutlet, depending on when you wanna show it and in which specific case. And then use the relative method startAnimating or stopAnimating in the right code flow (It really depends on how you have structured all the previous bullet points).
Since your question was very general and it includes a lot of sub-steps, basically it really needs to be thorough studied and analysed.
I've tried to sum up as much as possible the most important bullet points. I hope the links i suggested to you will help a little bit. Good luck.
I am designing an idle clicker style app, as I am quite new to programming and thought it would be a good personal project. However I am trying to design the upgrades on a second ViewController menu, however every time that the user leaves the first ViewController, all the settings on that page are lost e.g. stats. I know that there are already similar questions, but they don't relate to my issue and I am having difficulties trying to understand them.
I was just wondering if someone had any way to save this progress both when the user moves to a new viewController and when the app is closed and reopened. Also this might be pushing it, but if you could describe what each part of the code does it would be very helpful.
Thanks
Best is to use UserDefaults to store page contents. You can define key/value pairs and save and load values as needed. Look for it in the IOS documentation. It is very easy to implement it.
This question already has answers here:
Force iphone app to restart programmatically?
(7 answers)
Closed 8 years ago.
I am developing an iPhone app in swift and wanted localisation feature inside it.
When the user selects a language in the app, the UI components such as labels/buttons,etc.,. fails to change the language and takes more time in some cases also.
So i needed to manually restart my app when the users want to change the language.
Can anyone please suggest me how to do that.
Thanks in advance.
Swift is a language, not an API. You have the same functionality available to you in Swift as in Objective C, although the syntax and ease of use may differ between the languages.
The answer you linked to therefore already answers the question.
Also, as Hemang points out, don't do this.
It's symptomatic of bad design that you would need to restart the app to change the displayed language.
It would be much better to fix the underlying problem than to apply a hacky band-aid solution such as this.
DONT EVER DO THIS... else you'll surely reject by Apple, I don't know what problem you're facing after user change different language from your app, because I'd worked on this kind of app before (which supports multiple language and user may able to change it while current running of the app). I don't have idea with Swift but in ObjectiveC it works perfect.
From Documentation, https://developer.apple.com/library/ios/qa/qa1561/_index.html
Warning: Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
NOT RECOMMENDED but still, you can ask user to Restart their app whenever they changed the language with proper message like, " needs to restart to take effect of language change, [please save your any on going work] and close and again open the app to see the effect, thanks !"
Here, the words inside <...> should be your app name, and [...] need to show if you're making an app that needs to save user information before exit?.
This question already has answers here:
Track all ObjC method calls?
(5 answers)
Closed 9 years ago.
I'm wondering if there is any way to log all method calls in iOS app? I know that I can add NSLog in every method which call I want to log, but I'm wondering if there is a simpler way? For example some internal mechanism which allow me to hook to all methods calls and fire some method/macro in that case. I simple words, how to catch method call and invoke other method before it? Is it even possible?
If you want to do that only for a couple of classes, then I think you could use the decorator pattern with NSProxy.
There is (albeit quite hidden) support for this already:
Just set an environment variable NSObjcMessageLoggingEnabled to YES
and look in the file: /tmp/msgSends-<processID>
The file should be easy to find if you are using the simulator (I only tested on a Simulator), but may require a jailbroken device to access the output on a device. I'll have a look to see if there is a way to route the output to a user defined file.
I regularly listen and watch the Stanford University iOS Programming Courses (CS193p) that are delivered by Paul Hegarty.
Even though these sessions move at a quick rate, they have proved valuable when it comes to learning the various topics covered.
In the latest series (Winter 2013) and in particular Lecture 2, Paul has made the comment disregard both the AppDelegate Interface & Implementation files created by XCode 4 when first creating a project and basically design your own Model.
Why do this if you have to redesign to include ‘window’ objects and the various application protocols when you can use the ones already provided to you in AppDelegate?
I think that you misunderstood the suggestion to "disregard the app delegate." Considering the application delegate's central location, it sometimes tends to become a "dumping ground" for everything shared. Need a flag or two? Throw it into the app delegate! Need a counter? No problem, put it into the app delegate! This is precisely the thing you should not be doing: storing the application state is something the model does; keep the app delegate out of it.
I do not think that the advice is to throw away the generated code for the app delegate, though: you need it to manage your application's lifecycle. But managing the lifecycle is the only thing for which you should be using your app delegate: your model classes need to be cleanly separated from it.