There are different ways to specify the allowed orientations for the app (both for the overall app and for individual screens).
The first way is through the implementation of this method in AppDelegate.swift
:
class AppDelegate: UIResponder, UIApplicationDelegate {
// ...
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return [.portrait, .landscapeLeft]
}
// ...
}
The above method specifies which orientations are allowed for the entirety of the app. For example, if one of your screens uses .portrait
and another screen uses .landscapeLeft
and .landscapeRight
, all three must be specified here.
If the method is not implemented, then Xcode will look to the orientations that are ticked in the Target's General tab as can be seen in the picture below:
In order to specify what orientations are allowed for specific UIViewController
s, the supportedInterfaceOrientations
property must be overridden to return the appropriate values.
Do note that if an orientation is specified in this property but is not allowed for the entirety of the app, then that orientation will not be allowed for the current UIViewController
.
class ViewController: UIViewController {
// ...
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return [.landscapeLeft, .portrait]
}
// ...
}
When displaying native alerts, the first thing that needs to be done is to create a UIAlertController
. A title, message, and "style" for the alert need to be specified to do this. The two styles that are supported by iOS are the .alert
style and the .actionSheet
style.
.alert |
.actionSheet |
---|---|
After that, UIAlertAction
s are to be added to the UIAlertController
(if needed) to allow the user to pick one of a certain set of options. There are also different styles that are allowed for each action: .cancel
, .default
, and .destructive
. You can look through their documentations here.
.alert |
.actionSheet |
---|---|
You may view the source code to see how to do this programmatically and how to respond to taps for each UIAlertAction
.
There are two types of persistence that are implemented in the app: one using Keychain (implemented using KeychainSwift package) and another using UserDefaults
.
The former is used for storing sensitive data that need to be stored securely, e.g. API tokens that are obtained from login APIs. The latter is used for non-sensitive data that you don't need to be stored securely.