HomeKit und SecureVideo

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • HomeKit und SecureVideo

    Hallo,

    ich wollte mir für mich selbst eine kleine App basteln, mit der ich auf einem iPad an der Wand, meine HomeKit Türklingel und das Türschloss steuern kann. Ich habe also eine Türklingel in Homekit, die hat einen Videostream und ein Knopf, sowie ein Micro und einen Lautsprecher und ich habe ein Türschloss in HomeKit, das meine Haustür entriegelt.

    Nun versuche ich seid 2 Tagen herauszufinden, wie ich das Video der Türklingel und auch den Snapshot den Homekit erzeugen kann, in eine Collection View Cell bekommen kann. ich finde so gut wie nichts dazu im Internet, außer der sehr dürftigen Apple Dokumentation und die hilft da irgendwie gar nicht weiter.

    Was ich schon herausgefunden habe ist, das die Homekit Kameras wohl mit Delegate Methoden funktionieren:

    Quellcode

    1. class DoorCollectionViewController: UICollectionViewController, HMCameraSnapshotControlDelegate, HMCameraStreamControlDelegate {
    2. var cameraLiveStream: HMCameraView!
    3. var selectedhome:HMHome!
    4. var doorBells: [HMAccessory] = []
    5. var doorLocks: [HMAccessory] = []
    6. var camProfiles:[HMCameraProfile] = []
    7. override func viewDidLoad() {
    8. super.viewDidLoad()
    9. findAccessories()
    10. for doorBell in doorBells {
    11. for camProfile in doorBell.cameraProfiles ?? [] {
    12. camProfiles.append(camProfile)
    13. camProfile.snapshotControl?.takeSnapshot()
    14. camProfile.streamControl?.startStream()
    15. }
    16. }
    17. }
    Alles anzeigen




    Quellcode

    1. func cameraStreamControlDidStartStream(_ cameraStreamControl: HMCameraStreamControl) {
    2. cameraLiveStream.cameraSource = cameraStreamControl.cameraStream
    3. }
    4. func cameraStreamControl(_ cameraStreamControl: HMCameraStreamControl, didStopStreamWithError error: Error?) {
    5. cameraLiveStream.cameraSource = nil
    6. }
    7. func cameraSnapshotControl(_ cameraSnapshotControl: HMCameraSnapshotControl, didTake snapshot: HMCameraSnapshot?, error: Error?) {
    8. cameraLiveStream.cameraSource = cameraSnapshotControl.mostRecentSnapshot
    9. }
    10. func cameraSnapshotControlDidUpdateMostRecentSnapshot(_ cameraSnapshotControl: HMCameraSnapshotControl) {
    11. cameraLiveStream.cameraSource = cameraSnapshotControl.mostRecentSnapshot
    12. }
    Alles anzeigen
    Was ich nicht hinbekomme, ist es IBOutlets auf mein Storyboard zu bekommen, die dann mal den Snapshot oder das Video anzeigen könnten, da ich im CollectionViewControler keine Outlets der CollectionViewCell verwenden kann. Und in der Cell weiß ich nicht wie ich das Delegate zuweisen soll, da es dort ja keine "viewDidLoad" Methode gibt.

    Hat von euch schon mal jemand was mit HomeKit gemacht und kann mir hier weiterhelfen?
  • Ich kenne mich zwar nicht mit Secure Video aus, aber es gibt einige Möglichkeiten den Delegate zu setzen.

    Zum einen kann das natürlich der CollectionViewController wenn er die Zelle erzeugt (cellForItemAt:) oder du nutzt die Methoden der Zelle awakeFromNib bzw. PrepareForReuse. Oder komplett anders, du nutzt ein ViewModel für die Zellen.

    Wenn du aber eh nur eine Klingel hast frage ich mich ob eine CollectionView das richtige ist. Ich habe keine Ahnung wie du dein UI haben willst, denke aber ein einfacher ViewController könnte ausreichen.
    Das Herz besitzt Gründe, die die Vernunft nicht kennt.
  • @pierredrks Danke für deine Antwort. Ich bräuchte da etwas mehr Informationen, denn so wie ich bisher die Delegates gesetzt habe, scheint es hier nicht zu gehen. Wenn ich also ein IBOutlet habe oder mir eine variable mache von dem Typ, den das Delegate benötigt, so wie hier:

    Quellcode

    1. class DoorCollectionViewController: UICollectionViewController, HMCameraSnapshotControlDelegate {
    2. let a = HMCameraSnapshotControl()
    3. override func viewDidLoad() {
    4. super.viewDidLoad()
    5. a.delegate = self
    6. }



    Crasht die Anwendung sofort mit der Begründung:



    Quellcode

    1. 2020-12-23 15:15:03.930444+0100 doorbell[4666:1265521] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Precondition not satisfied: lock'
    2. *** First throw call stack:
    3. (0x1ae9c59d8 0x1c2d2eb54 0x1d9fe2420 0x1c29418d0 0x1040bca14 0x1040bcac8 0x1b0b69098 0x1b0b6d650 0x1b0b6da30 0x1b0aa1988 0x1b0ab5e00 0x1b0ab7230 0x1b0a9a0c8 0x1b1738448 0x1b1c3df2c 0x1b1c444d0 0x1b1c4f820 0x1b1b9b160 0x1b1bc5324 0x1b125e5a8 0x1ae94487c 0x1ae93ef50 0x1ae93f498 0x1ae93eba0 0x1c567c598 0x1b122e3d8 0x1b1233958 0x1c20a3b54 0x1040c28e8 0x1040c2860 0x1040c292c 0x1ae61d568)
    4. libc++abi.dylib: terminating with uncaught exception of type NSException
    5. *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Precondition not satisfied: lock'
    6. terminating with uncaught exception of type NSException
    Und collection View, weil ich die Türschlösser auch noch dazu haben möchte und auf der Collectionview Cell soll schon der Snapshot der Camera zu sehen sein. Und weil es evtl in den Store kommt und es dort sicher Leute gibt, die mehr als eine Türklingel haben und...... und.... und..... ;)
  • Wenn du willst kannst du dein Projekt mal hier hochladen, dann können ich oder andere einmal drüber schauen. Die Exception als solche sagt erstmal nicht viel, wobei lock zumindest auf ein threading Problem hinweisen könnte, bzw. Falsche Anwendung der API.

    Ich würde aber an deiner Stelle erst einmal auf CollectionView usw. verzichten und versuchen die Preview und was du sonst haben willst für ein Device ans Laufen zu bekommen ohne dass du dich um evtl. entstehende Probleme durch Verwendung einer CollectionView kümmern musst. Sprich ein Problem nach dem anderen angehen.
    Das Herz besitzt Gründe, die die Vernunft nicht kennt.
  • Hier habe ich Beispiel Code von Apple gefunden:


    Quellcode

    1. // Example - Take and display snapshot from the camera accessory
    2. importHomeKit ...
    3. let cameraAccessory : HMAccessory = ...
    4. if let cameraProfile = cameraAccessory.cameraProfiles?.first { cameraProfile.snapshotControl?.takeSnapshot() }
    5. let snapshotView = HMCameraView()
    6. // MARK: HMCameraSnapshotControlDelegate
    7. func cameraSnapshotControl(_ cameraSnapshotControl: HMCameraSnapshotControl, didTake snapshot: HMCameraSnapshot?, error: NSError?) {
    8. if error == nil {
    9. snapshotView.cameraSource = snapshot
    10. } else {
    11. // Error handling
    12. } }
    Alles anzeigen
    Sieht für mich aus, wie das was ich habe, hier wird auch nirgendwo ein Delegate gesetzt. Aber die Funktion cameraSnapshotControl wird nie aufgerufen, wenn ich cameraProfile.snapshotControl?.takeSnapshot() ausführe!
  • Qvex23 schrieb:

    Quellcode

    1. class DoorCollectionViewController: UICollectionViewController, HMCameraSnapshotControlDelegate {
    2. let a = HMCameraSnapshotControl()
    3. override func viewDidLoad() {
    4. super.viewDidLoad()
    5. a.delegate = self
    6. ...
    Die HMCameraSnapshotControl Instanz erstellst Du nicht selber, sonder die holst Du dir aus dem Profil, HMCameraProfile, raus. Dann kannst du das Delegate setzen.
  • Hast du fast oben gepostet.

    Quellcode

    1. if let cameraProfile = cameraAccessory.cameraProfiles?.first { cameraProfile.snapshotControl?.takeSnapshot() }


    Nur dass du dann

    Quellcode

    1. if let cameraProfile = cameraAccessory.cameraProfiles?.first { cameraProfile.snapshotControl?.delegate = self
    2. }
    schreibst
    Das Herz besitzt Gründe, die die Vernunft nicht kennt.