Post

Replies

Boosts

Views

Activity

Reply to Run something before another thing
Here you go: Full Code - https://developer.apple.com/forums/content/attachment/894f8e48-e35b-4ee0-937b-438560656346 Also I have accidentally activated and had to remove a breakpoint before. However, I don't know what they do or how to use them.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to In App Settings
That didn't work to check, nothing happened with the switch. Here is my current Home.swift code: import UIKit import SafariServices import UserNotifications class Home: UIViewController, UNUserNotificationCenterDelegate {         @IBOutlet weak var leadingHome: NSLayoutConstraint!     @IBOutlet weak var trailingHome: NSLayoutConstraint!          var menuOut = false          static var riddleNotification = Bool()     override func viewDidLoad() {         super.viewDidLoad()                  //Ask for Notification Permision         let center = UNUserNotificationCenter.current()         center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in         }                           func riddleNotification() {                          //Notification Content             let content = UNMutableNotificationContent()             content.title = "Check out this weeks riddle!"             content.body = "This weeks riddle is..."             content.categoryIdentifier = "riddle"                          //Notification Trigger             let date = Date().addingTimeInterval(5)                          var dateComponents = DateComponents()             //dateComponents.hour = 9             //dateComponents.minute = 30             //dateComponents.weekday = 4 //Wednesday             let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)                          //Create Request                          let uuidString = UUID().uuidString             let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)                          //Register Request             center.add(request) { (error) in                 //Check the parameter and handle any errors             print("riddle notification scheduled")         }         }                  if (UDM.shared.defaults.object(forKey: "riddleNotification") != nil) {             center.delegate = self                     center.getNotificationSettings(completionHandler: { (settings) in                             if settings.authorizationStatus == .notDetermined {                                     // Notification permission has not been asked yet, go for it!                                     // Notification permission was previously denied, go to settings & privacy to re-enable                                     center.requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in                                                                                          DispatchQueue.main.async {                                                     // Enable or disable features based on authorization.                                                     if !granted {                                                             let alert = UIAlertController(title: NSLocalizedString("Notification ", comment: ""), message: "", preferredStyle: .alert)                                                             alert.message = NSLocalizedString("Notifications disabled: Activate in Settings.", comment: "")                                                             alert.addAction(UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .cancel) { _ in                                                                     // continue your work                                                             })                                                                                                                          self.present(alert, animated: true, completion: nil)                                                     }                                             }                                     }                             } else if settings.authorizationStatus == .denied {                                     DispatchQueue.main.async {                                             let alert = UIAlertController(title: NSLocalizedString("Notification ", comment: ""), message: "", preferredStyle: .alert)                                             // Enable or disable features based on authorization.                                             alert.message = NSLocalizedString("Notifications disabled: Activate in Settings.", comment: "")                                             alert.addAction(UIAlertAction(title: NSLocalizedString("ok", comment: ""), style: .cancel) { _ in                                                     // continue your work                                                 Home.riddleNotification = false                                                 UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")                                             })                                                                                          self.present(alert, animated: true, completion: nil)                                     }                             } else if settings.authorizationStatus == .authorized {                                     // Notification permission was already granted                                 Home.riddleNotification = true                                 UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")                                 riddleNotification()                             }                     })         }         if let value = UDM.shared.defaults.value(forKey: "riddleNotification") as? Bool {             Home.riddleNotification = value             }         if Home.riddleNotification == true {                  riddleNotification()                 }         else if Home.riddleNotification == false {                         print("no riddle notification scheduled")                 }        }          @IBAction func Riddles(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://riddles.com")!)                  present(vc, animated: true)     }          @IBAction func RiddlesandAnswers(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://riddlesandanswers.com")!)                  present(vc, animated: true)     }          @IBAction func menuTappedHome(_ sender: Any) {                  if menuOut == false {             leadingHome.constant = 150             trailingHome.constant = -150             menuOut = true         }         else {             leadingHome.constant = 0             trailingHome.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {             self.view.layoutIfNeeded()         }) { (animationComplete) in             print("The animation is complete")         }     }   } class UDM {         static let shared = UDM()     let defaults = UserDefaults(suiteName: "com.riddlewednesday.saved.data")! }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Notifications and ViewControllers
AppDelegate: import UIKit import Firebase @main class AppDelegate: UIResponder, UIApplicationDelegate {     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {         // Override point for customization after application launch.         FirebaseApp.configure()         return true     }     // MARK: UISceneSession Lifecycle     func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {         // Called when a new scene session is being created.         // Use this method to select a configuration to create the new scene with.         return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)     }     func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {         // Called when the user discards a scene session.         // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.         // Use this method to release any resources that were specific to the discarded scenes, as they will not return.     } } TheRiddle ViewController: import SafariServices import WebKit import Firebase class TheRiddle: UIViewController {          @IBOutlet weak var leading_TheRiddle: NSLayoutConstraint!     @IBOutlet weak var trailing_TheRiddle: NSLayoutConstraint!          @IBOutlet weak var CurrentRiddle: UILabel!     @IBOutlet weak var PreviousRiddle: UILabel!          var menuOut = false          override func viewDidLoad() {         super.viewDidLoad()                  let db = Firestore.firestore()                  db.collection("TheRiddle").document("Riddles").getDocument { (document, error) in                          //check for error             if error == nil {                 //check if document exists                 if document != nil {                 }else {                     if let currentRiddle = document!.get("CurrentRiddle") as? String {                         self.CurrentRiddle.text = "This Weeks Riddle: " + currentRiddle                     }                     if let previousRiddle = document!.get("CurrentRiddle") as? String {                         self.CurrentRiddle.text = "Previous Riddle: " + previousRiddle                     }                 }             }                      }                       }               @IBAction func RiddleAnswerForm(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://forms.office.com/Pages/ResponsePage.aspx?id=ytAqTDte6UK-KD5v_kOm4Y843IzqmYtFlDtLrfRYsi1UMFpUMk1GN01GS05BVFlJUElONk4yR1hKUCQlQCN0PWcu")!)                  present(vc, animated: true)     }          @IBAction func menuTappedTheRiddle(_ sender: Any) {                  if menuOut == false {             leading_TheRiddle.constant = 150             trailing_TheRiddle.constant = -150             menuOut = true         }         else {             leading_TheRiddle.constant = 0             trailing_TheRiddle.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {             self.view.layoutIfNeeded()         }) { (animationComplete) in             print("The animation is complete")         } } }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to In App Settings
Home ViewController: import UIKit import SafariServices import UserNotifications class Home: UIViewController {               @IBOutlet weak var leadingHome: NSLayoutConstraint!     @IBOutlet weak var trailingHome: NSLayoutConstraint!          var menuOut = false          static var riddleNotification = Bool()               override func viewDidLoad() {         super.viewDidLoad()                  //Ask for Notification Permision         let center = UNUserNotificationCenter.current()                  center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in         }                  func riddleNotification() {                          //Notification Content             let content = UNMutableNotificationContent()             content.title = "Check out this weeks riddle!"             content.body = "This weeks riddle is..."             content.categoryIdentifier = "riddle"                          //Notification Trigger             let date = Date().addingTimeInterval(5)                          var dateComponents = DateComponents()             //dateComponents.hour = 9             //dateComponents.minute = 30             //dateComponents.weekday = 4 //Wednesday             let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)                          //Create Request                          let uuidString = UUID().uuidString             let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger)                          //Register Request             center.add(request) { (error) in                 //Check the parameter and handle any errors         }         }                           if let value = UDM.shared.defaults.value(forKey: "riddleNotification") as? Bool {             Home.riddleNotification = value         }        if Home.riddleNotification == true {         riddleNotification()        }        else if Home.riddleNotification == false {                print("no riddle notification scheduled")        }         else {                  let isRegisteredForRemoteNotifications = UIApplication.shared.isRegisteredForRemoteNotifications         if isRegisteredForRemoteNotifications {              // User is registered for notification             Home.riddleNotification = true             UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")         }         else {              // Show alert user is not registered for notification             Home.riddleNotification = false             UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")         }            riddleNotification()         }        }          @IBAction func Riddles(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://riddles.com")!)                  present(vc, animated: true)     }          @IBAction func RiddlesandAnswers(_ sender: Any) {         let vc = SFSafariViewController(url: URL(string: "https://riddlesandanswers.com")!)                  present(vc, animated: true)     }          @IBAction func menuTappedHome(_ sender: Any) {                  if menuOut == false {             leadingHome.constant = 150             trailingHome.constant = -150             menuOut = true         }         else {             leadingHome.constant = 0             trailingHome.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {             self.view.layoutIfNeeded()         }) { (animationComplete) in             print("The animation is complete")         }     }      } class UDM {          static let shared = UDM()          let defaults = UserDefaults(suiteName: "com.riddlewednesday.saved.data")!      } Settings ViewController: import UIKit class Settings: UIViewController {          @IBOutlet weak var leading_Settings: NSLayoutConstraint!     @IBOutlet weak var trailing_Settings: NSLayoutConstraint!     @IBOutlet var riddleSwitch: UISwitch!          var menuOut = false          override func viewDidLoad() {         super.viewDidLoad()                  if Home.riddleNotification == true {             riddleSwitch.setOn(true, animated: true)         }                  if Home.riddleNotification == false {             riddleSwitch.setOn(false, animated: true)         }     }          @IBAction func menuTappedSettings(_ sender: Any) {                  if menuOut == false {             leading_Settings.constant = 150             trailing_Settings.constant = -150             menuOut = true         }         else {             leading_Settings.constant = 0             trailing_Settings.constant = 0             menuOut = false         }         UIView.animate(withDuration: 0.2, delay: 0.0, options: .curveEaseIn, animations: {             self.view.layoutIfNeeded()         }) { (animationComplete) in             print("The animation is complete")         } }     @IBAction func riddleSwitchDidChange(_ sender: Any) {         if riddleSwitch.isOn {                      Home.riddleNotification = true             UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")             }         else {             Home.riddleNotification = false             UDM.shared.defaults.setValue(Home.riddleNotification, forKey: "riddleNotification")         }     }      }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Why is this crashing?
Could you please give me an example? This is what is not running:                         if IconChange.setIconPurchased == true {                             print("purchased = true")                             self.iconSelected = self.names[indexPath.row]                             UserDefaults.standard.setValue(self.names[indexPath.row], forKey: "iconSelected")                             self.IconSelector.reloadData()                             tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark                             IconChange.pushBack = true                             self.navigationController?.popViewController(animated: true) Also, I am mysteriously getting the index out of range error and crashing again.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Why is this crashing?
Thank you for the help with streamlining it. I couldn't figure that out earlier. As for where it crashes, it prints it fine and then crashes at cell.textLabel?.text = unlocked[indexPath.row], if I comment that out it crashes when setting the image.
Topic: Programming Languages SubTopic: Swift Tags:
May ’21
Reply to Why is this crashing?
Would you like me to give you my project so you can run it? The if I am talking about is on line 15 and it is supposed to prompt to get purchased if not purchased already, and then refresh and select it. However, the if on line 15 is running before you purchase it. Thank you for all the help you two!
Topic: Programming Languages SubTopic: Swift Tags:
May ’21