Posts

Post not yet marked as solved
0 Replies
113 Views
Hi, I'm adding steps: First launch I set LoginAndRegisterContainerView with navigationcontroller func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {      guard let windowScene = (scene as? UIWindowScene) else { return }         let contentView = LoginAndRegisterContainerView() //    let window = UIWindow(windowScene: windowScene)    let navigationView = UINavigationController(rootViewController: UIHostingController(rootView: contentView))    window.rootViewController = navigationView    self.window = window    window.makeKeyAndVisible()   } Later in MyView I want to change rootViewController DispatchQueue.main.async {               let vc = UIHostingController(rootView: Home())       let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as! SceneDelegate       let window = sceneDelegate.window       window?.rootViewController = vc               UIView.transition(with: window!, duration: 0.4, options: .transitionFlipFromRight, animations: {}, completion:                  { completed in         // maybe do something on completion here       })      } is it the right way?( at the end my view hierarchy looks like this:
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
2 Replies
520 Views
I want to pick an image with PHPickerViewController. But this causes to memory link. Can anyone help me with this issue?( I created ImagePickerManager and I'm using it on ViewController below. P.s: I didn't get a leak when writing the same code with UIImagePickerViewController. import Foundation import Photos import PhotosUI class ImagePickerManager: NSObject {   // MARK: Variables   var accessType: PHAccessLevel = .addOnly   var pickerViewController = PHPickerViewController(configuration: PHPickerConfiguration())   //var viewController: UIViewController?   var pickImageCallback : ((UIImage) -> ())?;   // MARK: Init   override init() {     super.init()     setupPhotoPicker()     setupPhotoLibrary(accessType)   } //  convenience init( //    viewController: UIViewController, //    accessType: PHAccessLevel = .addOnly) { //      self.init() // //      self.viewController = viewController //      setupPhotoLibrary(accessType) //      setupPhotoPicker() //    }   // MARK: Setup   private func setupPhotoLibrary(_ accessType: PHAccessLevel) {     self.checkAuthorizationStatusForPhotoLibrary()     self.accessType = accessType   }   private func setupPhotoPicker() {     pickerViewController.delegate = self   }   // MARK: Present PickerController   func presentPHPicker(_ viewContr: UIViewController,_ callback: @escaping ((UIImage) -> ())) {     pickImageCallback = callback    // self.viewController = viewContr     viewContr.present(pickerViewController, animated: true)   }   // MARK: Checking status of Photo library access   func checkAuthorizationStatusForPhotoLibrary() {     switch PHPhotoLibrary.authorizationStatus(for: accessType) {     case .authorized: break     case .notDetermined:       self.requestAuthorizationForPhotoLibrary()     case .denied:       self.showAccessDeniedMessage()     default: return     }   }   // MARK: Request to Access Photo Library   func requestAuthorizationForPhotoLibrary () {     PHPhotoLibrary.requestAuthorization(for: accessType) { status in       switch status {       case .authorized:         print("Access granted")       case .denied: break       case .notDetermined: break       default: return       }     }   }   // MARK: Access Denied to do action   private func showAccessDeniedMessage() {     print("\n ShowAccessDeniedMessage \n")   } } // MARK: - PHPickerViewControllerDelegate extension ImagePickerManager: PHPickerViewControllerDelegate, UINavigationControllerDelegate {   func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {     picker.dismiss(animated: true, completion: nil)     for result in results {       result.itemProvider.loadObject(ofClass: UIImage.self, completionHandler: { (object, error) in         if let image = object as? UIImage { //          DispatchQueue.main.async {             // Use UIImage             self.pickImageCallback?(image) //          }         }       })     }   } } /// -------- ViewController let imageManager = ImagePickerManager()   @objc func pressedButton() {     imageManager.presentPHPicker(self) { image in       print("something...")     }   }
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
0 Replies
140 Views
I'm trying to show multiple cells and their own data models in the same tableView. I added segment control for this and I delete all tableview current data and removed the current data sources and binding new data and its cell. But I am getting the below error message :( If you have any offers please help me :( P.s: Each segment's cells and sections design is different than each other. Error: Thread 1: "attempt to insert section 0 but there are only 0 sections after the update" In View Model: private func bindSelectedSegmentIndex() { /// reset pagination and limit for new request selectedSegmentIndex .observe(on: MainScheduler.instance) .do(onNext: { _ in /// remove all old api data in tableviews self.transactionsAndDepositsTableViewData.accept([]) self.contractsTableViewData.accept([]) self.pagination = Pagination() self.updateTableViewDataSource.accept(()) }) .subscribe(onNext: { [weak self] _ in guard let self = self else {return} switch self.selectedSegmentIndex.value { case 0,1: self.callUserTransactionsAndDeposits() case 2: self.getContracts() default: return } }) .disposed(by: disposeBag) } In ViewController: @IBAction func segmentControlChanged(_ sender: UISegmentedControl) { self.hapticImpactMedium() let selectedIndex = sender.selectedSegmentIndex self.viewModel.selectedSegmentIndex.accept(selectedIndex) } fileprivate func setupTransactionsAndDepositsDataSource() { transactionsTableViewDataSource = TableViewSectionedAnimatedDataSourceWithRx(cell: WithdrawAndDepositCell.self, data: WithdrawAndDepositSection.self) transactionsTableViewDataSource?.handleCell = { cell ,item in cell.item = item } transactionsTableViewDataSource?.dataSource.titleForHeaderInSection = { dataSource, index in return dataSource.sectionModels[index].header } } fileprivate func setupContractsDataSource() { contractsTableViewDataSource = TableViewSectionedAnimatedDataSourceWithRx(cell: ContractTableViewCell.self, data: ContractTableSection.self) contractsTableViewDataSource?.handleCell = { cell ,item in cell.item = item } contractsTableViewDataSource?.dataSource.titleForHeaderInSection = { dataSource, index in return dataSource.sectionModels[index].header } } private func setDataSources(with index: Int) { /// remove old dataSource and update new one tableView.dataSource = nil tableView.delegate = nil switch index { case 0,1 : setupTransactionsAndDepositsDataSource() /// Bind tableViewData to the tableView items for transactionsTableViewDataSource viewModel.transactionsAndDepositsTableViewData.asDriver() .drive(tableView.rx.items(dataSource: transactionsTableViewDataSource.dataSource)) .disposed(by: disposeBag) case 2: setupContractsDataSource() /// Bind tableViewData to the tableView items for clientsTableViewDataSource viewModel.contractsTableViewData.asDriver() .drive(tableView.rx.items(dataSource: contractsTableViewDataSource.dataSource)) .disposed(by: disposeBag) default : break } }
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
2 Replies
296 Views
Hi. Can I set a time and run any code at a specific time? For example after 2 days. But the application will not run or be in background mode. I've read about Background Tasks. But everyone runs their code in background mode (in-app run). I want to make that special time :) Thanks in advance
Posted
by Kanan27.
Last updated
.
Post marked as solved
1 Replies
239 Views
Hi everyone. I want to bind the URLSessionDelegate protocol with the custom protocol that it confirmed from URLSessionDelegate. But I can't catch its functions on the protocol. Can you tell me where I went wrong?
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
1 Replies
544 Views
Hi. I am adding AppTrackingTransparency to my application. I have added all requirements from documentation and regularly alert shows when the app launches. The problem is related to real devices. I achieve to display privacy alert on the simulator but can't do this on the real phone. How can fix this issue, please help me? P.s ios version: 15 Xcode version: 13
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
2 Replies
941 Views
Guideline 5.1.2 - Legal - Privacy - Data Use and Sharing The app privacy information you provided in App Store Connect indicates you collect data in order to track the user, including Crash Data. However, you do not use App Tracking Transparency to request the user's permission before tracking their activity. Starting with iOS 14.5, apps on the App Store need to receive the user’s permission through the AppTrackingTransparency framework before collecting data used to track them. This requirement protects the privacy of App Store users. I am getting this rejected message from apple. But I added AppTrackingTransparency to my project and alerts when the app launches. What must I do for the next step? P.s I am using Firebase's Crashlytics. struct AppDelegateHelper {   static func askAppTrackingTransparency() {     // Request user authorization to access app-related data for tracking the user or the device.     if #available(iOS 14, *) {       ATTrackingManager.requestTrackingAuthorization { status in         switch status {         case .authorized:           print("Allowed to AppTrackingTransparency")           break                     case .denied: break         case .notDetermined: break         case .restricted: break         }       }     } else {       // Fallback on earlier versions       print("Can't ask AppTrackingTransparency")     }   } }
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
0 Replies
253 Views
Hey everyone. I have created a new framework, may I create a new bundle for my assets, xib... can I keep it inside itself?
Posted
by Kanan27.
Last updated
.
Post marked as solved
1 Replies
430 Views
Hi. How can we set structure complex in ui. For example, if we imagine have app's main content contains some ui - different collection views, another sections and end of all we have comments which is shows another page's bottom area. I think I'll solve it with creating different viewcontrollers - one for collection views, another for comment section... and with addchild i'll add all of that to Main controller. Is this way is well ? CommentController which is gets comments and adding that section to some controller what i want. is this right ?
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
3 Replies
597 Views
I'm trying reload all cells when variable was changed. Problem was appearing only in bottom cell of tableView. TableView scrolling unexpected way (it was scrolling top and bottom) func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { guard let cell = tableView.cellForRow(at: indexPath) as? ConverterTableViewCell, let code = cell.currency.text else { return } cell.priceText.text = "0" convertCurrencyForCode(with: code) cell.priceText.delegate = self cell.priceText.addTarget(self, action: #selector(textChanged(_:)), for: .editingChanged) cell.priceText.addTarget(self, action: #selector(onTextFieldTap), for: .touchDown) writedNumber = 0 tableView.reloadData() cell.priceText.becomeFirstResponder() selected = indexPath.row } @IBAction func textChanged(_ textField: UITextField) { if let text = textField.text { writedNumber = Double(textField.text!) tableView.reloadData() } }
Posted
by Kanan27.
Last updated
.
Post not yet marked as solved
0 Replies
263 Views
I'm trying to add a settings navigation controller to my tabBar. The problem is tab bar has navigation items when opening the page. And. I want to add settings controller their navigation items (title, right button). When I trying to add it, setting was coming under the tabBar's navigation. How I fix it? class TabFirst: UIViewController {   override func viewDidLoad() {     super.viewDidLoad()           let storyboard = UIStoryboard(name: "Main", bundle: nil)     let vc     = storyboard.instantiateViewController(identifier: "SettingsViewController")           present(vc, animated: true, completion: nil)   }     }
Posted
by Kanan27.
Last updated
.
Post marked as solved
8 Replies
660 Views
Hi. I'm trying to create dynamic localization, but I getting an error. Please, someone, help me :) class LocalizationManager {   var currentBundle = Bundle.main         let manager = FileManager.default   lazy var bundlePath: URL = {     let documents = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!)     let bundlePath = documents.appendingPathComponent(RuntimeLocalizable.bundleName, isDirectory: true)     return bundlePath   }()       public func returnCurrentBundleForLanguage(lang:String) throws -> Bundle {     if manager.fileExists(atPath: bundlePath.path) == false {       return Bundle(path: getPathForLocalLanguage(language: lang))!     }     do {       let resourceKeys : [URLResourceKey] = [.creationDateKey, .isDirectoryKey]       _ = try manager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)       let enumerator = FileManager.default.enumerator(at: bundlePath ,                               includingPropertiesForKeys: resourceKeys,                               options: [.skipsHiddenFiles], errorHandler: { (url, error) -> Bool in                                 return true       })!       for case let folderURL as URL in enumerator {         _ = try folderURL.resourceValues(forKeys: Set(resourceKeys))         if folderURL.lastPathComponent == ("\(lang).lproj"){           let enumerator2 = FileManager.default.enumerator(at: folderURL,                                    includingPropertiesForKeys: resourceKeys,                                    options: [.skipsHiddenFiles], errorHandler: { (url, error) -> Bool in                                     return true           })!           for case let fileURL as URL in enumerator2 {             _ = try fileURL.resourceValues(forKeys: Set(resourceKeys))             if fileURL.lastPathComponent == "languages.strings" {               return Bundle(url: folderURL)!             }           }         }       }     } catch {       return Bundle(path: getPathForLocalLanguage(language: lang))!     }     return Bundle(path: getPathForLocalLanguage(language: lang))!   }       private func getPathForLocalLanguage(language: String) -> String {     return Bundle.main.path(forResource: language, ofType: "lproj")!   }       func setCurrentBundle(forLanguage:String){     do {       currentBundle = try returnCurrentBundleForLanguage(lang: forLanguage)     }catch {       currentBundle = Bundle(path: getPathForLocalLanguage(language: "en"))!     }   } } ///// import Foundation public final class RuntimeLocalizable {       public typealias LanguageKey = String   public typealias Language = Dictionary<String, String>   public typealias Translations = Dictionary<LanguageKey, Language>       let tableName: String   let translations: Translations       static let bundleName = "RuntimeLocalizable.bundle"   let manager = FileManager.default       lazy var bundlePath: URL = {     let documents = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!)     print("\n   DIRECTORY: \(documents.absoluteString)\n")           let bundlePath = documents.appendingPathComponent(RuntimeLocalizable.bundleName, isDirectory: true)     return bundlePath   }()       public init(translations: Translations, name: String) {     tableName = name     self.translations = translations   }       func clean() throws {     // TODO: There can be multiple table names in the same Bundle. So only remove the bundle if there is no more string files.     var langFiles: Dictionary<String, Int> = [:]           for item in manager.enumerator(at: bundlePath, includingPropertiesForKeys: nil, options: [.skipsPackageDescendants])! {       print(item)     }     if manager.fileExists(atPath: bundlePath.path) {       try manager.removeItem(at: bundlePath)     }   }       public func bundle() throws -> Bundle {           if manager.fileExists(atPath: bundlePath.path) == false {       try manager.createDirectory(at: bundlePath, withIntermediateDirectories: true, attributes: nil)     }           for language in translations {       let lang = language.key       let langPath = bundlePath.appendingPathComponent("\(lang).lproj", isDirectory: true)       if manager.fileExists(atPath: langPath.path) == false {         try manager.createDirectory(at: langPath, withIntermediateDirectories: true, attributes: nil)       }               let sentences = language.value       let res = sentences.reduce("", { $0 + "\"\($1.key)\" = \"\($1.value)\";\n" })               let filePath = langPath.appendingPathComponent("\(tableName).strings")       let data = res.data(using: .utf32)       manager.createFile(atPath: filePath.path, contents: data, attributes: nil)                       print(res)     }           let localBundle = Bundle(url: bundlePath)!     return localBundle   } } /////////// func localized() -> String {     return NSLocalizedString("entertainment_header", tableName: "", bundle: LocalizationManager().currentBundle, value: "", comment: "")   }
Posted
by Kanan27.
Last updated
.