I use AVFoundation to read the QR Code, after reading I get a string, the pattern "WIFI:S:name-of-network;T:WPA;P:password;;" How do I decode, with the ability to connect, and output separately password, name in label.text
I am new to swift, I would be grateful if you could describe the solution to the problem in detail. Thank you.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have two arrays, I call a separate VC and change the General array to Motivation by clicking the button. When I return to the VC on which UIViewCollection, the displayed array element remains equal to the index of the previous one. How do I start displaying the array from scratch?
VC UIcollectionView
class MainViewController: UIViewController, UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
@IBOutlet weak var collectionView: UICollectionView!
var generalQuote = [
Text(text: "general0", name: "quote0"),
Text(text: "general1", name: "quote1"),
Text(text: "general2", name: "quote2"),
Text(text: "general3", name: "quote3"),
Text(text: "general4", name: "quote4"),
]
var motivationQuoute = [
Text(text: "motivation0", name: "quote0"),
Text(text: "motivation1", name: "quote1"),
]
var arrayQuote = [Text]()
enum Theme {
case general, motivation
}
var currentTheme: Theme = .general
var quoutesInTheme = 0
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.register(UINib(nibName: "ProductCell", bundle: nil),forCellWithReuseIdentifier: "ProductCell")
self.collectionView.dataSource = self
self.collectionView.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
checkCurrentTheme()
print("Updated")
}
func checkCurrentTheme() {
switch currentTheme {
case .general:
print("Current theme General")
quoutesInTheme = generalQuote.count
arrayQuote = generalQuote
case .motivation:
print("Current theme Motivation")
arrayQuote = motivationQuoute
quoutesInTheme = motivationQuoute.count
}
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
quoutesInTheme = arrayQuote.count
return quoutesInTheme
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCell", for: indexPath) as! ProductCell
let quotes: Text
quotes = arrayQuote[indexPath.item]
cell.setupCell(text: quotes)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
let guide = view.safeAreaLayoutGuide
let width = guide.layoutFrame.size.width
let height = guide.layoutFrame.size.height
return CGSize(width: width, height: height)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 5
}
}
VC with Buttons
class choiceThemeQuoteViewController: UIViewController {
@IBOutlet weak var general: UIButton!
@IBOutlet weak var motivation: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func generalButton(_ sender: Any) {
if let presenter = presentingViewController as? MainViewController {
presenter.currentTheme = .general
presenter.collectionView.reloadData()
}
dismiss(animated: true, completion: nil)
}
@IBAction func motivationButton(_ sender: Any) {
if let presenter = presentingViewController as? MainViewController {
presenter.currentTheme = .motivation
presenter.collectionView.reloadData()
}
dismiss(animated: true, completion: nil)
}
}
I get on the output wrong decibel value when silent get 0.00 if I create noise goes up to 0.02 - 0.03. Something I do wrong, because I measured with another application with silence, I get about 20 db, with noise about 50 db.
struct NoiseMeterView: View {
let audioRecorder: AVAudioRecorder
@State var timer: Timer?
@State var decibels: Float = 0
init() {
let audioFileURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("audio.m4a")
let settings = [
AVFormatIDKey: Int(kAudioFormatMPEG4AAC),
AVSampleRateKey: 16000,
AVNumberOfChannelsKey: 1,
AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
]
do {
audioRecorder = try AVAudioRecorder(url: audioFileURL, settings: settings)
} catch let error {
fatalError("Error creating audio recorder: \(error.localizedDescription)")
}
}
var body: some View {
VStack {
Text("Noise Level: \(String(format: "%.2f", decibels)) dB")
.font(.title)
.padding()
Button(action: {
if timer == nil {
startMetering()
} else {
stopMetering()
}
}) {
Text(timer == nil ? "Start" : "Stop")
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
func startMetering() {
do {
try AVAudioSession.sharedInstance().setCategory(.record)
try AVAudioSession.sharedInstance().setActive(true)
} catch let error {
print("Error setting up audio session: \(error.localizedDescription)")
return
}
audioRecorder.isMeteringEnabled = true
audioRecorder.record()
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in
audioRecorder.updateMeters()
var decibels = audioRecorder.peakPower(forChannel: 0)
decibels = min(max(decibels, -120), 0)
self.decibels = pow(10, (decibels / 20))
}
}
func stopMetering() {
timer?.invalidate()
timer = nil
audioRecorder.stop()
}
}
I want to use Google Ads to promote my Ios app. After setting up the company, I was given a message indicating that I need to set up a conversion to install.
I have already installed the Firebase SDK in my xcode project. Now I need to understand where and what exactly to configure on the Firebase site. And how to add tracking to the application itself.
P.S Working with Firebase and Google Ads for the first time, so maybe something is not so understand as it is in reality. I would be grateful for a detailed guide on how to set everything up properly.