I've got an iOS app in which it starts differently if the user has been logged in through Facebook account or not.
So the application flow is as follows:
1- I call app delegate, which creates a navigationController and shows it.
2- In the root view controller, it checks if the user is logged in or not. By default (for example during the first boot) it loads view controllers as not logged in, showing only contents for not logged user. if the user is logged with Facebook account it sends requests to a server and shows the contents for logged in user. The requests start with didupdatelocation delegated method, from which it gets the current location.
3- there are many places in which the app asks if you want to log in. If the user gets correct login, it creates a new navigation controller, as in app delegate, and displays it. The problem is that in this way it doesn't call the method didupdatelocation, and so it doesn't get current location and doesn't make any request to server.
How can you suggest me to solve the problem?
Your design should not rely on didUpdateLocation to be called. This method is called at non-predictable intervals by the system.
One way to force it to call however, is to stop the locationManager and start it again.
startUpdatingLocation
stopUpdatingLocation
However, I recommend you consult the CLLocationManager Class Reference and re-design your login check accordingly.
Related
Just starting out iOS development.
When starting my app, I'd like it to check if the user has a known account and if they do, "login" by acquiring an access token and then display the main / first view. If they don't have an account or if login fails, they should be redirected to a login / registration screen.
Initially I thought I'd hide this process (check for account + call to get access token) behind a splash screen, but apparently this is against Apples guidelines. Is there a common / recommended way to do this on iOS?
By referencing to application:didFinishLaunchingWithOptions: you can read that this method is good for initializing.
Use this method (and the corresponding
application:willFinishLaunchingWithOptions: method) to complete your
app’s initialization and make any final tweaks. This method is called
after state restoration has occurred but before your app’s window and
other UI have been presented. At some point after this method returns,
the system calls another of your app delegate’s methods to move the
app to the active (foreground) state or the background state. This
method represents your last chance to process any keys in the
launchOptions dictionary. If you did not evaluate the keys in your
application:willFinishLaunchingWithOptions: method, you should look at
them in this method and provide an appropriate response. Objects that
are not the app delegate can access the same launchOptions dictionary
values by observing the notification named
UIApplicationDidFinishLaunchingNotification and accessing the
notification’s userInfo dictionary. That notification is sent
shortly after this method returns.
There may be several ways. But using singleton for token and launching your app is one of the best ways. As you might not need to use that launcher class again. Just for checking user have token and if yes then show main view otherwise login view.
Hope it helps you !!
How do I refresh all my UIViews to show the data for the new user.
(Scenario: User1 logs out and User2 logs in without closing the app.)
Right now I have a Logout button on my userVC. Upon pressing it the current user is logged out and the login view is presented. If a new user logs in the view dismisses and shows the userVC again. The userVC, because it was never refreshed keeps showing the data of the old user. (This is also true for all other VCs in this tabbed application.)
How do I get the views to reload their data? (Or redraw?)
There are several ways you can achieve this, but the first thing you should do is add an ACL to your userdata so that User2 does not have access to User1's data! Security is something you must take seriously when handling data for multiple users.
More info: https://parse.com/docs/ios/guide#security
If you log in a user, you could call a method for fetching the data. How is the data for your view retrieved? Whatever code you're using to fetch user data for the view, make sure this code is in its own function so that you can call it again upon login.
Update
Call the getInfo() in viewWillAppear() or viewDidAppear() instead. If that is too often, you can set a flag when a user logs in so that getInfo() is called only if it's a newly logged in user.
I have an iOS app that uses Core Location to get the user's location, which pops up the request for permission on the first attempts. However, there are moments where the user will not be able to operate the screen, so at these times I don't want to ask for a location. I check before each call to CLLocationManager startUpdatingLocation, and set map views to not show the user location. The problem is that there is still something trying to access the use location, as the permissions popup is still shown, and I am unable to find where this happens.
So, what other actions could trigger this? And, probably most useful: is there a way I can set a symbolic breakpoint on something that fires always whenever access to the current location is requested? I tried setting one on [UIAlertView show], but that doesn't fire, presumably because the alert is shown by the system, rather than my app?
I have an iOS application where I need to persist a set of data after the application HARD CLOSES (when the user double clicks the Home button and slides the application upwards). Then, when the application comes back to the foreground, I need to fetch that data and do something with it. I'm just not sure where I need to put that logic for Application Hard Close and Resuming the Application.
In your AppDelegate
When your app is going to be closed, but still in Multitasking menu the following method is getting called
-(void)applicationWillResignActive:(UIApplication*)application
If after 3 minutes user doesn re-open your app this method is going to be called
-(void)applicationDidEnterBackground:(UIApplication*)application
If user re-opens your app from multitasking menu the following method is getting called
-(void)applicationWillEnterForeground:(UIApplication*)application
If user is going to close your app from multitasking menu this method is getting called(you will have limited time to perform some logic here)
-(void)applicationWillTerminate:(UIApplication*)application
When user presses home twice applicationWillResignActive and applicationDidEnterBackground is called. You can save data here.
When user opens app, applicationWillEnterForeground is called, you get data which you save and process.
When a user hard-closes the application, the UIViewController's Delegate's method called applicationWillTerminate. Here I can catch and save the model data before it's all destroyed.
Then when a user launches the application again, there are many choices like didFinishLaunchingWithOptions where I can grab the data stored to disk.
Your app no longer gets an applicationWillTerminate call ever. You are simply silently killed while in the background. You have to write your app to save state in the applicationDidEnterBackground handler, as nmh describes. That's your only option.
The second time I tried to authorize an app in Facebook it gives me back a window
You have already authorized app name. Press okay to continue.
The question is what is called back/delegate that is called after I press okay, because I somehow need a way to remove the login view controller after this
The callback is the same as when you wasn't authorized. Same process.
Back in your application you don't even have to (and even can't) make the distinction.
In your UIApplicationDelegate, be sure that the - (BOOL)application:handleOpenURL: method calls - (BOOL)handleOpenURL: on the Facebook object.