How to be notified when UISplitViewController pops to master on iPhone mode? - ios

I am using a UISplitViewController on iPhone 6 Plus, and I wish to be notified when in portrait mode the user goes back to the master view controller (i.e. when the split view acts like a navigation controller).
Moreover I wish to be notified in my UISplitViewDelegate the same way I am already notified when the user pushes the detail view controller (via the splitViewController:showDetailViewController:sender: callback)
Do you know the easiest (and cleanest) way to do it?
Thanks in advance.

In depends on what version of iOS we are trying to do that.
iOS 8.0~8.2 way your project should not be compatible with iOS 7 and will work ONLY iOS 8 and UP the best way is to use Size Classes (Trait collections) presented on WWDC 2014 and there was a video about this way, Session 214 "View Controller Advancements in iOS 8"
Briefly it now has a property
This property indicates if detail view is collapsed.(Session 214, Minutes 12:30 ->)
#property (getter=isCollapsed) BOOL collapsed;
A bit of KVO magic and you could have a callback of when detail view is available.
For old iOS 7 way you can detect current orientation of device and get current state of your detail.
Couple methods(rotation callbacks) you have:
willRotateToInterfaceOrientation:duration:
didRotateFromInterfaceOrientation:
interfaceOrientation
!!! BASED on Session 214(43:20) it is not recommended to use these methods with iOS 8 and UP because they are deprecated!!!
I'm not sure this 2 way are the best and easiest but they work properly as expected.And little advice to look WWDC videos, they are pretty helpful.

To be notified on MasterViewController's return, you'll have to create a delegate and set it to the DetailViewController, in performSegueWithIdentifier for example.
If so, when you will go back to master, the delegate will be fired.

Because show detail is adaptive, i.e. it either pushes on the master nav in compact width or sets as the split's secondary in regular width and you only want to know when the detail is popped, you'll instead need to use the master navigation controller's delegate which you can also set your app delegate to be.

Related

IOS initial view controller based on condition retrieved from database

An iOS app I'm creating shows a setup screen upon first launch which requires data to be written to the database.
Upon launch, I need to access this value form the database.
If it is set, launch main view controller
Else show setup view controller.
As far as I'm aware theres two ways I can do this, programmatically setting it from the AppDelegate or using an initial View Controller as a splash screen and performing the look up and segue there.
What would be the best way to approach this? Is it wrong to do a database lookup in didFinishLaunchingWithOptions?
Using a splash screen is probably the better option as it provides better scope for modification in the future and allows you to update the user on progress. It is fine for the app delegate to run logic to determine how the app starts but you should endeavour to keep the app delegate minimal and focussed.
I very much doubt that you would get this approved (if your goal is the App Store). Your app delegate needs to create a window, and set a rootViewController to that window before it returns YES in appFinishLaunching:
You simply do not have enough time to check with a server before creating the first viewController and you'll be creating poor interface if you try. I suggest the first ViewController will need to be informing the user that it is checking with the server with an activityIndicator or something. The best :)

Global app remote notification response ios

I would like to implement a similar response system for push notifications throughout my app. When a remote notification appears and the application is in the active state I would like to place a button temporarily on the screen that performs the same action regardless of where it is in the app.
The only way I can think to do this is to create the same response to notification method in each of the app's many view controller.
Is there any way to do this in the app delegate, tab bar, or navigation bar so that the same response would apply to multiple views rather than placing the same function in each view controller separately?
Please advise and thanks
If I understood your question correctly: your problem is not related to notifications at all, but rather how to place a button on top of all views. A common way would be to add it as a subView to the window.
As a starting point: AwesomeMenu on GitHub

Unity iOs - screen gets black when changing rotation while Unity is paused

I have a unity app, that uses Vuforia AR library. I extended this app with some iOs code. I wanted to be able to display my custom UIViewControllers sometimes instead of the main view controller that Unity uses. But I want to be able to switch back. I.e: I have a button that opens UIViewController with "About app" information and this controller then has "Exit" button to return to Unity controller.
This is my code for adding the new controller instead of the Unity View Controller:
self.unityRootController = self.keyWindow.rootViewController; // keep reference to the Unity Controller
self.keyWindow.rootViewController = controller; // display my own controller
// this pauses the unity and qcar -> so that QCAR doesn't try to recognize objects, when Unity Controller is not up
QCARUnityPlayer::getInstance().QCARPause(true);
UnityPause(true);
Then when returning from my own controller to Unity controller:
self.keyWindow.rootViewController = self.unityRootController; // return to Unity Controller
// start tracking with QCAR and unpause Unity View
QCARUnityPlayer::getInstance().QCARPause(false);
UnityPause(NO);
This works fine except one case, that's caused me to pull my hair ever since encountering it. My app supports changing orientation of screen in both Unity and ObjectiveC code. And this is the trouble: If I open my View Controller while the device is for example in Portrait Orientation, then turn the device to Landscape orientation, my controller gets correctly rotated. But if I at this moment want to close my custom view controller and return to unity controller, the screen gets black suddenly. After rotating the device to portrait orientation, the unity controller suddenly starts working as expected.
I'd like the unity controller to start directly after closing my custom view controller even if the screen orientation is changed. I suppose I have to add some code after I start again the Unity Player here:
QCARUnityPlayer::getInstance().QCARPause(false);
UnityPause(NO);
// TODO: supposedly some code should go here, that fixes black screen
But I tried to find something in the AppController.mm, that is builded by Unity and I could not find anything, that would help me. I found few lines of unity code, that had the word "orientation" in it, but I tried to use that code and didn't help. Does anybody know, what should I do, please? Thanks a bunch :)
Not sure if you have fixed this, Its been a while... But the reason that your UnityViewController is not functioning properly is because a view controller that is not visible will not receive rotation events. Because you are setting your view controller as the root view controller, the UnityDefaultViewController defined in "iPhone_View.mm" is not receiving rotation events.
I have been studying Unity's rotation for a while now as I have my own issue with a similar setup.
There are a few things that you might be able to try:
In iPhone_View.mm there is a function that is defined called: UpdateOrientationFromController(UIViewController* controller) that might be able to solve your problem. You would want to call this function on the view controller that you designed yourself where you placed your //TODO comment. That function calls a few key functions and methods that handle Unity's interface orientations:
ConvertToUnityScreenOrientation: for some reason Unity Uses their own defined screen orientations, this internally converts the orientation to what Unity uses.
QCARUnityPlayer::getInstance().QCARSetOrientation(): QCAR Also needs its orientation to be set
UnitySetScreenOrientation(_curOrientation): The unity library has an internal way of checking the screen orientation at every rendered frame. I think this function sets an internal flag for the Unity View to check in CheckOrientationRequest() defined in iPhone_View.h as well.
AppController_RenderPluginMethodWithArg is called, I am not sure what this does, but I think it does something important
OrientTo(_curOrientation): this kicks off the actual orientation change and handles the right calls. This includes the call to AppController's onForcedOrientation: method that does the final orientation.
You may be able to call AppController's onForcedOrientation: method directly with a UnityScreenOrientation after you convert a UIDeviceOrientation to a UnityScreen Orientation with ConvertToUnityScreenOrientation() defined in iPhone_OrientationSupport.h. You may not want to call this method directly though, because there are quite a few things that are involved with Unity's orientation methods. You would do this when your app returns from presenting your view controller.
The last thing, and the "hackiest thing" that you can do, that will get the job done, but not in the most efficient way, is to add UnityDefaultViewController to your ViewController as a child ViewController with the addChildViewController: UIViewController Docs, or maybe as just a property, and then override the willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation:in your ViewController and after calling super, pass the message to the UnityDefaultViewController. This will cause the UnityDefaultViewController to update the UnityView every time the orientation changes, even though the view isn't actually visible. You may or may not need to unpause Unity in order for this to function.
Of the three methods, the last one should definitely work, because I have implemented it myself. However, the first one should work as well, because Unity uses it several times to check the devices current orientation from the splash screen.
Hope this helps!

How do I make sure when I change to different views each is set as the First Responder?

I have an app that uses a tab bar controller with 5 different tabs using one viewcontroller (UIViewController). On the primary viewcontroller there is an audio function to play audio and when I switch to other views, I am no longer able to use the headset buttons to make adjustments to audio playback (play/stop). I am told that I need to make each view act as a First Responder so it can receive the notification to adjust audio playback. How do I do this?
I am only using one UIViewController for the entire app, should I setup different view controllers for each tab of the application instead?
I'm using xCode 4.6.4
iOS SDK 6.1
Thanks.

iOS 5 View events order change

Has anyone noticed that the order in which view events are fired in iOS 5 has changed? Using a Tab Bar switching from one view to another, the order in iOS 4 was: "viewWillDisappear" and then "viewWillAppear". In iOS 5 they are switched. Is it possible to use iOS 5 but have the previous order of events?
This is true.
Seems that the tab's viewDidLoad now gets called BEFORE the app delegate's didFinishLaunchingWithOptions.
I had the app launch initialising something and the viewDidLoad customising it. IOS 5 messed it up until I made the app init routine leave things alone if they had been setup.
I am guessing that you need to be prepared for this and either make your code check in each place that nothing is being undone or corrupted by the other.

Resources