Cannot run Apple's Haptic Sampler (sample project from Apple's website)

376 Views Asked by At

I downloaded a sample project from here(haptic sampler) and I cannot run because of several issues. I solved signing identifier.

The error messages say:

  • ~/PlayingACustomHapticPatternFromAFile/HapticSampler/ViewController.swift:66:19: Type 'CHHapticEngine.StoppedReason' has no member 'gameControllerDisconnect'

  • ~/PlayingACustomHapticPatternFromAFile/HapticSampler/ViewController.swift:68:19: Type 'CHHapticEngine.StoppedReason' has no member 'engineDestroyed'

if I delete these parts, another error says:

  • Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Here are my questions.

  1. Do same issues happen to you?

  2. How can I fix this problem?

Here's my environment specification.

  • macOS Catalina 10.15.6
  • Xcode 11.6
  • iPhone 7 iOS 13.6

enter image description here

3

There are 3 best solutions below

2
On BEST ANSWER

The problem is that the enum cases

.gameControllerDisconnect

And

.engineDestroyed

Were introduced in iOS 14, Xcode 12 beta. But you are running an earlier version so, as the error message says, they don’t exist.

1
On

Replace the following lines of ViewController.swift Line 48 in the createEngine() function.

if engine == nil {
    print("Failed to create engine!")
}

With:

guard let engine = engine else {
    print("Failed to create engine!")
    return
}

That should resolve the compile + runtime errors you're currently getting

4
On

Haptic feedback needs an actual device since it uses a vibration motor. It can not be run on a simulator. That is why you are getting the error message "Failed to create engine!". To fix it connect to an actual device and select a team in "Signing & Capabilities" and run.