Presenting a modal view controller from within Settings.app - ios

I decided to use InAppSettingsKit for my app. However, certain settings require the user to use the audio input for custom setting. I was wondering whether there is a way of presenting a modal view controller from within Settings.bundle - getting the parent view controller that presents Settings.app to sense that a button/setting was changed and launch another view controller on top of this one to pick the new setting from audio input and pass it on to the setting.bundle?

InAppSettingsKit comes with an extension that allows you to do exactly this.
Check the Custom ViewControllers section in the Readme.
Of course this works only within the app, not in the settings app. There are several option to differentiate the settings plists between Settings.app and in-App. See "Custom inApp plists".

There is no default mechanism for communication between Settings.bundle and your open app. The only way they can pass data between each other would be through NSUserDefaults.
If you were so inclined, you could store values into NSUserDefaults to indicate the last View Controller you had open, but it would have to be a manual process. Even if that were achieved, there is no place in Settings.bundle to perform logic to consume that value.

Related

How can I test a specific screen in my app without navigating all hierarchy until there

Say you are developing Settings.app (the iPhone settings app) and you want to add features in the Text Replacement system.
To test that screen one must go through all the screens Settings > General > Keyboard > Text replacement which is very painful if you do it often.
What are the options to directly test the Text Replacement screen? Or, alternatively, to go the specific screen quickly?
Have in mind that usually we set things up on the previous screens: state, singletons, global variables, etc…
I know there's no magic way to do it. What I'd like to know then is what are your tricks and advices (you use different schemes? you organize your state code in a way that's easier to test the screen?)
You can use storyboards initialViewController checkbox for this purpose. In Storyboard -> ViewController check for property called initialViewController. By enabling this you will directly navigate to that specific screen. Please ignore, if this is not your requirement.
If you dont make that screen apart from other code, it will be really hard, move all the setup from the previous screen to app delegate and set that screen as rootViewcontroller
I usually add a test button that I can hide later in production. You can set it up to skip login but also could include an other code you want in there or go straight to the view you want. I have the button to different functions that can change so that I don't have to add and remove anything else afterwards, just hide the button again or redirect to a new function. You might have to mock some data in your case but if you are just checking the UI as you build it then this is a good quick test method.
if you are using storyboard Select Viewcontroller which you want to test and in storyboard check initialViewController checkbox for this purpose,
so it will launch as your first screen so without navigating to all other screen you can check checkbox of initialViewController.

Is there a standard iOS UI control which implements open-in like UI?

I want to build open-in like UI (see picture below).
It should include a list of icons representing actions and cancel button. I want pretty much UIAlertController only with icons (vs plain text).
Is there a standard iOS control which does something like or that or will I have to build/find a custom UI control for that?
From Apple's docs, each displayed service/action is a UIActivity, which is an abstract class, displayed in a UIActivityViewController which you can customize. There are several built-in services, and you can create your own w/custom icons. Yes, UIActionSheet was deprecated in iOS8.
The UIActivityViewController class is a standard view controller that
you can use to offer various services from your application. The
system provides several standard services, such as copying items to
the pasteboard, posting content to social media sites, sending items
via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing
this view controller. Configuration for the view controller involves
specifying the data objects on which the view controller should act.
(You can also specify the list of custom services your app supports.)
When presenting the view controller, you must do so using the
appropriate means for the current device. On iPad, you must present
the view controller in a popover. On iPhone and iPod touch, you must
present it modally.
Also see this related question on some image gotchas ...
And this tutorial on adding a custom UIActivity to the view.

UIActivityViewController vs UIDocumentInteractionController in ios

I just read some articles on UIActivityViewController and UIDocumentInteractionController in iOS, but I am very confused about how to use them because both seem the same.
So, when do I use UIActivityViewController or UIDocumentInteractionController?
Is there any difference for Open In... & use UIActivityViewController?
I am very confused about how to use them. Please clarify to me their specific use.
In short, UIDocumentInteractionController deals with files while UIActivityViewController deals with various other services in your app. I'm not one to criticize much but you really should at least try to google and read at least the overview in the iOS Developer Docs.
UIDocumentInteractionController documentation:
A view controller that previews, opens, or prints files whose file format cannot be handled directly by your app.
...
Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file. For example, an email program might use this class to allow the user to preview attachments and open them in other apps.
After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display.
You can also use the delegate to participate in interactions occurring within the presented interface. For example, the delegate is notified when a file is about to be handed off to another application for opening. For a complete description of the methods you can implement in your delegate, see UIDocumentInteractionControllerDelegate.
UIActivityViewController documentation:
A view controller that you use to offer standard services from your app.
...
The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.
Basically UIActivityViewController shares Data Objects (like Strings or Images) where UIDocumentInteractionController shares whole Documents / Files f.e. a PDF.

UIActionSheet-like control similar to iOS 7 Safari's

I'm trying to create a UIActionSheet similar to Safari's. I haven't been able to find anything in the Apple documentation on how to make a UIActionSheet look like this. Is there a control/API that I am missing that I can use to create what's below, or am I stuck with creating my own UIView and displaying that?
Ninja Edit: This appears to be a UIActivityViewController. Is there any way I can add my own custom actions to it?
That is not a UIActionSheet.
It is a UIActivityViewController:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIActivityViewController_Class/Reference/Reference.html
From Apple's Documentation:
The UIActivityViewController class is a standard view controller that you can use to offer
various services from your application. The system provides several standard services,
such as copying items to the pasteboard, posting content to social media sites, sending
items via email or SMS, and more. Apps can also define custom services.
Your app is responsible for configuring, presenting, and dismissing this view controller.
Configuration for the view controller involves specifying the data objects on which the
view controller should act. (You can also specify the list of custom services your app
supports.) When presenting the view controller, you must do so using the appropriate means
for the current device. On iPad, you must present the view controller in a popover. On
iPhone and iPod touch, you must present it modally.
About the ninja edit : Yes you can add actions to the UIActivityViewController.
See UIActivity on Apple's doc, or this SO question.

How to develop dynamic iOS settings menu

if you are developing Android apps, you can just create a PreferenceScreen/Activity and then link some preference items which are declared in a xml file to that screen. So you can build different settings menus and call them from different places in your app. They all use the same style and the same mechanism to save the settings chosen.
I was just wondering, that there is no such function in iOS. We have to call many different settings menus in our app, so how do I archive this? Is it better to design one dynamic settings screen which you can call from anywhere in your app (filled with different information each time), or should we use one big settings menu where all the app-settings live. Is it possible then, to simply jump to "submenus" of this big settings menu?
Should I use iOS Settings Bundle to generate the menu structure in files and then display them in an tableview?
I could find some Settings-Kits like InAppSettingsKit but I don't like to use an open source library for such an important function.
The settings bundle is the right way to add settings to your app.
It's a bit unusual to access settings from within an iOS app, but if you're sure you want to do so then InAppSettingsKit is a good a way to make the in-app settings as similar to the settings app as possible. The fact that it's open source shouldn't put you off - much of the iOS toolchain is open source.
I did a similar thing where I have an enum of menu modes. Each time the a table view cell is selected it changes the mode and redraws the table view. conditionals in numberOfRowsInSection: and numberOfSections: change the layout of the table and conditionals in cellForRowAtIndexPath: change the content, all based on the new mode set. I then spun the content of the table for each mode out into a JSON file and at the beginning read that into a Dictionary which forms the data structure that the table reads from.
I chose JSON as it's easily parsable with NSJSONSerialization

Resources