Post

Replies

Boosts

Views

Activity

Search for HC-05 Bluetooth device via Bluetooth
Good afternoon guys, I want to create an app that's detects common bluetooth based credit card skimmers predominantly found in gas pumps. The app scans for available bluetooth connections looking for a device with title HC-05. If found, the app will attempt to connect using the default password of 1234. Once connected, the letter 'P' will be sent. If a response of 'M' then there is a very high likelihood there is a skimmer in the bluetooth range of your phone (5 to 15 feet). I can show you the code I already have: class ScanViewController: UIViewController, CBPeripheralDelegate, CBCentralManagerDelegate {          // Properties Back-End         private var centralManager: CBCentralManager!         private var peripherals: [CBPeripheral] = []         private var peripheral: CBPeripheral!         override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .systemGroupedBackground                  centralManager = CBCentralManager(delegate: self, queue: nil)            }     //MARK: - Back-End          // If we're powered on, start scanning            func centralManagerDidUpdateState(_ central: CBCentralManager) {                print("Central state update")                if central.state != .poweredOn {                    print("Central is not powered on")                } else {                    print("Central scanning for", ParticlePeripheral.skimmerDeviceUUID);                    centralManager.scanForPeripherals(withServices: [ParticlePeripheral.skimmerDeviceUUID],                                                      options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])                }            }          // Handles the result of the scan            func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {                // We've found it so stop scan                self.centralManager.stopScan()             print("Stopped to scan")                // Copy the peripheral instance                self.peripheral = peripheral                self.peripheral.delegate = self                // Connect!                self.centralManager.connect(self.peripheral, options: nil)                         }          // The handler if we do connect succesfully             func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {                 if peripheral == self.peripheral {                     print("Connected to Skimmer Scammer")                     peripheral.discoverServices([ParticlePeripheral.skimmerDeviceUUID])                 }             }          // Handles discovery event             func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {                 if let services = peripheral.services {                     for service in services {                         if service.uuid == ParticlePeripheral.skimmerDeviceUUID {                             print("Skimmer Scanner service found")                             //Now kick off discovery of characteristics                             peripheral.discoverCharacteristics([...], for: service)                             return                         }                     }                 }             } class ParticlePeripheral: NSObject {         // I think thats the uuid for HC-05         public static let skimmerDeviceUUID     = CBUUID.init(string: "00001101-0000-1000-8000-00805F9B34FB")     } I googled around for hours but I wasn't able to find a solution and I have never worked with Bluetooth connections before, that makes it really difficult but I tried. My questions: is the code I already have valid? How to can I connect via pin code? "1234" I would be so helpful if someone here has some advices for me, thanks in advance!
1
0
3.0k
Feb ’22
UICollectionView Layout Error: nil layout parameter
Hey guys, when I run my project the error: 'UICollectionView must be initialized with a non-nil layout parameter', appears. I don't know why because I already used the same code in another project and it worked. This is my code:  var myCollectionView : UICollectionView? func setUpContactsCollectionView() {         let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()         layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)         layout.itemSize = CGSize(width: 100, height: 100)         layout.scrollDirection = .horizontal                myCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)         myCollectionView?.showsHorizontalScrollIndicator = false                  myCollectionView?.register(InserateCollectionCell.self, forCellWithReuseIdentifier: "InserateCollectionCell")         myCollectionView?.backgroundColor = UIColor.white                  myCollectionView?.dataSource = self         myCollectionView?.delegate = self   myCollectionView?.translatesAutoresizingMaskIntoConstraints = false         myCollectionView?.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true         myCollectionView?.topAnchor.constraint(equalTo: topAnchor, constant: 50).isActive = true         myCollectionView?.widthAnchor.constraint(equalTo: widthAnchor).isActive = true         myCollectionView?.heightAnchor.constraint(equalTo: heightAnchor).isActive = true     } Thanks in advance!
12
0
3k
Jan ’22
Swift Firebase Error: Thread 1: "Failed to get FirebaseDatabase instance: Specify DatabaseURL within FIRApp or from your databaseForApp:URL: call."
Hey guys, I want to connect my Xcode Project with Firebase to load my Userdata into the database. Although I already used the same code in another project, it doesn't work and throws me the following offer: Thread 1: "Failed to get FirebaseDatabase instance: Specify DatabaseURL within FIRApp or from your databaseForApp:URL: call." Here is my Code: @objc func registerButtonTapped() {         if acceptTermsOfUseSwitch.isOn == true && emailTextField.text?.isEmpty == false && passwordTextField.text?.isEmpty == false {             print("Register...")             //Authentification         Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (data, error) in             if let err = error {                 print(err.localizedDescription)                 return             }             guard let newUser = data?.user else { return }             let uid = newUser.uid             print("User: \(String(describing: newUser.email)) wurde erstellt, ID: \(String(describing: newUser.uid))")             //Database             self.uploadUserData(uid: uid, email: self.emailTextField.text!)             }         } else {             print("No valid data")         }     } func uploadUserData(uid: String, email: String) {         var ref = DatabaseReference()         ref = Database.database().reference().child("users").child(uid)                 print("Datenbank ID: \(ref)")                 ref.setValue(["email" : email, "userID" : uid])                 print("User data uploaded")                 //Change VC:             let vc = TabBarController()                 self.dismiss(animated: true, completion: {              UIApplication.shared.windows.first?.rootViewController = vc             })             } I hope someone can help me, thanks in advance!
2
0
1.4k
May ’21
Push data to other VC with protocol, error: force unwrapped a nil value
Hey guys, my problem: I have to different VC's with textFields, and I need their text on the third ViewController, I use a two protocols to push the textfield text as data to the third VC. Here are the two Protocols: protocol RegisterNameProtocol {     var name: String? { get set } } protocol RegisterNumberProtocol {     var phoneNumber: String? { get set } } I implemented the variables in the two vc's and afterwards I tested the functionality with print statements, it worked! Now I need them in the third VC, this is my code yet but it throws the following error: force unwrapped a nil value The third VC: weak var nameDelegate: RegisterNameProtocol? weak var phoneDelegate: RegisterNumberProtocol?     var phoneNumber = ""     var name = "" func xyzzy() { phoneNumber = (phoneDelegate?.phoneNumber)!         name = (nameDelegate?.name)! } I hope someone can help me! Thanks in advance
7
0
743
May ’21
Search for HC-05 Bluetooth device via Bluetooth
Good afternoon guys, I want to create an app that's detects common bluetooth based credit card skimmers predominantly found in gas pumps. The app scans for available bluetooth connections looking for a device with title HC-05. If found, the app will attempt to connect using the default password of 1234. Once connected, the letter 'P' will be sent. If a response of 'M' then there is a very high likelihood there is a skimmer in the bluetooth range of your phone (5 to 15 feet). I can show you the code I already have: class ScanViewController: UIViewController, CBPeripheralDelegate, CBCentralManagerDelegate {          // Properties Back-End         private var centralManager: CBCentralManager!         private var peripherals: [CBPeripheral] = []         private var peripheral: CBPeripheral!         override func viewDidLoad() {         super.viewDidLoad()         view.backgroundColor = .systemGroupedBackground                  centralManager = CBCentralManager(delegate: self, queue: nil)            }     //MARK: - Back-End          // If we're powered on, start scanning            func centralManagerDidUpdateState(_ central: CBCentralManager) {                print("Central state update")                if central.state != .poweredOn {                    print("Central is not powered on")                } else {                    print("Central scanning for", ParticlePeripheral.skimmerDeviceUUID);                    centralManager.scanForPeripherals(withServices: [ParticlePeripheral.skimmerDeviceUUID],                                                      options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])                }            }          // Handles the result of the scan            func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {                // We've found it so stop scan                self.centralManager.stopScan()             print("Stopped to scan")                // Copy the peripheral instance                self.peripheral = peripheral                self.peripheral.delegate = self                // Connect!                self.centralManager.connect(self.peripheral, options: nil)                         }          // The handler if we do connect succesfully             func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {                 if peripheral == self.peripheral {                     print("Connected to Skimmer Scammer")                     peripheral.discoverServices([ParticlePeripheral.skimmerDeviceUUID])                 }             }          // Handles discovery event             func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {                 if let services = peripheral.services {                     for service in services {                         if service.uuid == ParticlePeripheral.skimmerDeviceUUID {                             print("Skimmer Scanner service found")                             //Now kick off discovery of characteristics                             peripheral.discoverCharacteristics([...], for: service)                             return                         }                     }                 }             } class ParticlePeripheral: NSObject {         // I think thats the uuid for HC-05         public static let skimmerDeviceUUID     = CBUUID.init(string: "00001101-0000-1000-8000-00805F9B34FB")     } I googled around for hours but I wasn't able to find a solution and I have never worked with Bluetooth connections before, that makes it really difficult but I tried. My questions: is the code I already have valid? How to can I connect via pin code? "1234" I would be so helpful if someone here has some advices for me, thanks in advance!
Replies
1
Boosts
0
Views
3.0k
Activity
Feb ’22
UICollectionView Layout Error: nil layout parameter
Hey guys, when I run my project the error: 'UICollectionView must be initialized with a non-nil layout parameter', appears. I don't know why because I already used the same code in another project and it worked. This is my code:  var myCollectionView : UICollectionView? func setUpContactsCollectionView() {         let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()         layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)         layout.itemSize = CGSize(width: 100, height: 100)         layout.scrollDirection = .horizontal                myCollectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)         myCollectionView?.showsHorizontalScrollIndicator = false                  myCollectionView?.register(InserateCollectionCell.self, forCellWithReuseIdentifier: "InserateCollectionCell")         myCollectionView?.backgroundColor = UIColor.white                  myCollectionView?.dataSource = self         myCollectionView?.delegate = self   myCollectionView?.translatesAutoresizingMaskIntoConstraints = false         myCollectionView?.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true         myCollectionView?.topAnchor.constraint(equalTo: topAnchor, constant: 50).isActive = true         myCollectionView?.widthAnchor.constraint(equalTo: widthAnchor).isActive = true         myCollectionView?.heightAnchor.constraint(equalTo: heightAnchor).isActive = true     } Thanks in advance!
Replies
12
Boosts
0
Views
3k
Activity
Jan ’22
Swift Firebase Error: Thread 1: "Failed to get FirebaseDatabase instance: Specify DatabaseURL within FIRApp or from your databaseForApp:URL: call."
Hey guys, I want to connect my Xcode Project with Firebase to load my Userdata into the database. Although I already used the same code in another project, it doesn't work and throws me the following offer: Thread 1: "Failed to get FirebaseDatabase instance: Specify DatabaseURL within FIRApp or from your databaseForApp:URL: call." Here is my Code: @objc func registerButtonTapped() {         if acceptTermsOfUseSwitch.isOn == true && emailTextField.text?.isEmpty == false && passwordTextField.text?.isEmpty == false {             print("Register...")             //Authentification         Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (data, error) in             if let err = error {                 print(err.localizedDescription)                 return             }             guard let newUser = data?.user else { return }             let uid = newUser.uid             print("User: \(String(describing: newUser.email)) wurde erstellt, ID: \(String(describing: newUser.uid))")             //Database             self.uploadUserData(uid: uid, email: self.emailTextField.text!)             }         } else {             print("No valid data")         }     } func uploadUserData(uid: String, email: String) {         var ref = DatabaseReference()         ref = Database.database().reference().child("users").child(uid)                 print("Datenbank ID: \(ref)")                 ref.setValue(["email" : email, "userID" : uid])                 print("User data uploaded")                 //Change VC:             let vc = TabBarController()                 self.dismiss(animated: true, completion: {              UIApplication.shared.windows.first?.rootViewController = vc             })             } I hope someone can help me, thanks in advance!
Replies
2
Boosts
0
Views
1.4k
Activity
May ’21
Push data to other VC with protocol, error: force unwrapped a nil value
Hey guys, my problem: I have to different VC's with textFields, and I need their text on the third ViewController, I use a two protocols to push the textfield text as data to the third VC. Here are the two Protocols: protocol RegisterNameProtocol {     var name: String? { get set } } protocol RegisterNumberProtocol {     var phoneNumber: String? { get set } } I implemented the variables in the two vc's and afterwards I tested the functionality with print statements, it worked! Now I need them in the third VC, this is my code yet but it throws the following error: force unwrapped a nil value The third VC: weak var nameDelegate: RegisterNameProtocol? weak var phoneDelegate: RegisterNumberProtocol?     var phoneNumber = ""     var name = "" func xyzzy() { phoneNumber = (phoneDelegate?.phoneNumber)!         name = (nameDelegate?.name)! } I hope someone can help me! Thanks in advance
Replies
7
Boosts
0
Views
743
Activity
May ’21