0

So I've made a very simple iOS app in SWiFT for the sake of experimentation that displays a string at the touch of a button I've successfully implemented and tested the watchOS version and it runs fine on my devices. What I want to do is add haptic .Click to the button in the watch app. Now I did some research and it says in ever article "it's easy just call it like this"

i started by Importing the WatchKit as stated in posts such as Where to find Taptic feedback API documentation or capabilities for watchOS 2?

import UIKit
import WatchKit


class ViewController: UIViewController {

    @IBOutlet weak var Button1: UIButton!

    @IBOutlet weak var LabelView: UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func ButtonPressed(sender: UIButton) {

// Directly Call the function in the Action     
WKInterfaceDevice.currentDevice().playHaptic(.Click)

    var myString = “Hello, World!”

        LabelView.text = “\(myString)”

    }
}

If this is the case (which I'm guessing it is not) then there is something wrong with my machine, or much more likely my code is wrong and more importantly I haven't understood the topic.

When I try to build the above example it fails at the Haptics line with the error:

"playHaptic" is unavailable. 

This is screaming include issues but I have

Import WatchKit

So I thought I was good and I'm forcing the .Click parameter so it looks ok but I've only been doing this a week so please forgive my lack of knowledge.

ANY AND ALL COMMENTS AND HELP ARE HUGELY APPRECIATED AS EVER!

I look forward to hearing from you all :)

EDIT:

iv also just read and experimented with the example HERE but when i try and repurpose it in my app its not happening.

i get the same errors like the libraries are not accessible.

do i need to import with the bridging method instead of directly in my swift file?

Community
  • 1
  • 1
MiRAGE
  • 95
  • 1
  • 8
  • Someone just mentioned that if i change my frameworks from iOS to WatchOs then i may have better luck, i have very little experience but tried converting it, but i needed to change the way the label is updated as LableView.text is not on in watchKit can i set it to `LabelView.setText("\(myString)")` ?? still though now only using the WK frameworks only having changed all my `IBactions` from `UIButton` to `WKInterfaceButton` and all my labels from `UILabel` to `WKInterfaceLabel ` as all i need is to set the string its very simple but i still get the error every time it reaches the haptic call – MiRAGE Feb 01 '16 at 05:55
  • If you look at the second example you linked, the taptic interface controller is running on the watch, not the phone. A phone isn't making the watch vibrate. You say you're making a watch app, but you're posting code for phone app. –  Feb 01 '16 at 06:58

1 Answers1

0

You're getting watchOS and iOS mixed up here. There's no playHaptic method on an iOS device.

While WKInterfaceDevice is available on iOS, its iOS methods are different from its watchOS methods.

The playHaptic method will work fine in your watch extension, but not in an iOS view controller.

If you're trying to activate taptic feedback on your watch when you press a button on your phone, you need to look into Watch Connectivity.

  • if i directly swap out the `UILabel` and `UIButton` for `WKInterfaceLabel` and `WKInterfaceButton` i can no longer access the .text variable of `WKInterfaceLabel` so i cant update the string after press. also im still geting a flag at the `playHaptic` line – MiRAGE Feb 01 '16 at 05:41