Skip to content

luisligunas/CSCI-181.03-Orientation-Alert-Persistence

Repository files navigation

CSCI 181.03 - Orientation, Alert, and Persistence

Orientation

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:

Target


In order to specify what orientations are allowed for specific UIViewControllers, 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]
  }
  // ...
}

Alert

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
Action Sheet Alert

After that, UIAlertActions 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
Screenshot 2023-04-11 at 3 30 52 AM Screenshot 2023-04-11 at 3 31 30 AM

You may view the source code to see how to do this programmatically and how to respond to taps for each UIAlertAction.

Persistence

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages