Is there way I can get current location without using UIViewController?
I'm making a SDK and I don't want to make UIViewController in it. I want to make only modal classes. I'm looking a way to avoid UIViewControllers completely for this SDK.
Thanks in Advance.
Related
I'm looking for a solution to track everything a UIViewController gets instantiated or is displayed on screen without using a base view controller as a superclass.
I know Firebase Analytics do it for the event screen_view, but haven't found a similar way to do it yet.
Any ideas on how to achieve this?
I'm creating an app that implements a Facebook and a Twitter service. In my view I have a button that toggles sharing on Facebook/Twitter or not. If Facebook/Twitter aren't connected, then the button will show "connect to".
When I click the button, a method in my controller (not my viewcontroller) will try to toggle the value because this controller tracks the state of my app. When I'm not connected to a social network my controller will notice and will call the correct service. This service will start a webview to provide the user credentials.
And now my question:
When I'm in my service and I need to provide credentials via a webview. When I want to show this webview I need to pass a View Controller that will handle the presenting. How do I provide a viewcontroller here?
Approaches I found:
Call the appdelegate singleton and get the current presenting
viewcontroller (I find this dirty but correct me if I'm wrong).
Since I'm injecting my service into my controller in
appdelegate.didFinishLaunchingWithOptions I could inject the UIWindow
of the appdelegate and ask for the current presenting viewcontroller
(Is almost the same as the first approach)
Create a protocol implemented by a viewcontroller. The service has a property that is equal to that protocol and in my app delegate inject the
viewcontroller into the service.
Have a property in your controller
that will be the presentingviewcontroller and let your controller
implement the approach #3 protocol. When a function of that protocol
is fired, the controller will handle it and use the
presentingviewcontroller property for the webview. I only need to
inject a viewcontroller into my controller in the appdelegate.
Don't implement anything view related in that service.
My current implementation is approach #3.
If some things are not clear, please let me know.
Any help is appreciated!
Thanks in advance!
I was hoping this question would of got more attention, I was interested to know how other people would handle this situation.
As you have already stated, there are a few ways to achieve what you need, but the answer depends on having knowledge of the application.
I would definitely try to keep business logic and UI as separate as possible, there are two methods that I can think of to do this, but they are pretty much the same thing.
Make the (non UI) controller responsible for the login check with a callback function, you can then leave the controller responsible for business logic and the calling ViewController responsible for rendering any UI as a result of that check.
As you suggested, using protocols, your controller could have a delegate that will be a ViewController that conforms to your protocol. Then usage would just be getting your shared instance, setting the delegate and calling the required fuctionality.
I would likely favor option 2 to be more Swift-like as it is a protocol orientated language.
If the controller is acting globally and accessed from anywhere within the application you could potentially end up duplicating a lot of code to make these checks, you could get around this by creating an extension of UIViewController which provides the functionality to interact with the controller.
I hope this helps, Would definitely be interesting to see the way other people would approach this.
How to achive facebook kind of SSO in iphone sdk?
(The way they open a view for login and loading).
I Don't want to use UIViewController and want to show Login/Loading view
and want to put Login/Loading code at one place
as that view is going to be opened from lots of controllers.
Is there any way to achieve this? (protocol?)
Not sure if this is what you mean, but the following tutorial shows a handy mechanism for allowing you to design a popup overlay window using a UIViewController.
http://blog.typpz.com/2013/12/09/ios-sdk-create-a-pop-up-window/
You design a UIViewController in storyboard which contains your overlay popup view. The surroundings remain transparent. You can create an instance of this UIViewController in your code and then ask it to overlay its view onto your existing controller view. The result is a popup window similar to a UIAlertView, into which you can put whatever you wish.
I use this for doing popup help overlays, but I image you could easily use it for your facebook like content.
Benefit 1) Since you design it in a UIViewController, you can use all the size class related layout and you can see how it will look on all the different device types.
Benefit 2) It is totally reusable. From any controller, create an overlay UIViewController instance and ask it to overlay its content on your current controller. Reverse is to ask it to remove the overlay.
I have a button and a related view which needs to be embedded in different ViewControllers in an iOS App. What is the recommended way of creating it? Should I create a ViewController with different views and use them in the components? Any pointers appreciated.
I am a newbie summoned with lot of Questions. I am working with UITabBarController Window base application. Is it necessary to Delegate UITabBarController to AppDelegate. Its working fine for me with both delegating and not delegating.
i got some idea of delegate while working with UITableViewController. Please let me know what will happen with and without delgating UITabBarController.
Please suggest any Material or PDF or Book where i can get good idea with AppDelegate other than Apple docs.
You should read about the Model-View-Controller (MVC) paradigm and how delegates fit into it. A good source would be Apple's document on the matter, as well as most beginning iPhone Development Books. I would suggest this one, and a good starting place for MVC is here.
To answer your specific question, you want your AppDelegate to implement the UITabBarControllerDelegate protocol " when you want to augment the behavior of a tab bar. In particular, you can use it to determine whether specific tabs should be selected, to perform actions after a tab is selected, or to perform actions before or after the user customizes the order of the tabs. After implementing these methods in your custom object, you should then assign that object to the delegate property of the corresponding UITabBarController object." (From Apple's Class Document here.
In simplified terms, you use it when you want to do something custom/specific when a viewController is selected from the tab bar (– tabBarController:didSelectViewController:)or will be (– tabBarController:shouldSelectViewController:). It can also be used to help with customizing the viewControllers showing on the tab bar if you have a need for more than allowed to be displayed at once (using a "More..." or whatever tab).